I have names and id's from listview in 2 different arraylist and would like to store id's and names from arraylist to string and then save them on a button click to sqlite.
The problem with below code is that when 2 items are checked and button is clicked the items are inserting twice. And when the id is set as UNIQUE then on insertion to 3 id's only one is saving in sqlite,...
This is what I have tried so far:
public void addSelected(ArrayList<String> selNames, ArrayList<String> selID) {
SQLiteDatabase db = getWritableDatabase();
try{
for (String str: selID){
for (String stl:selNames){
ContentValues cv = new ContentValues();
cv.put(KEY_ID, str);
cv.put(KEY_STATUS, stl);
db.insertOrThrow(TABLE_SELECTED, null, cv);
}
}
db.close();
}catch (Exception e){
Log.e("Problem", e + " ");
}
}