I have some situation. In my expandableListView adapter (BaseAdapter), I have method onDrop to change position of child item by drag.
public void onDrop(int[] from, final int[] to) {
if (to[0] > notesList.size() ||
to[0] < 0 || to[1] < 0 ||
to[1] > notesList.size() + 1 ||
(taskList.size()) == to[0] || taskList.size() - 1 == from[0])
return;
Note replacedValue = getValue(from);
Note currentValueOnNewPosition = notesList.get(to[0]).get(to[1]);
Task task1 = taskList.get(from[0]);
Task task2 = taskList.get(to[0]);
int oldTaskName = replacedValue.getTaskName();
int newTaskName = currentValueOnNewPosition.getTaskName();
if (currentValueOnNewPosition.getState() == 1L)){
return;
} else {
notesList.get(from[0]).remove(from[1]);
notesList.trimToSize();
notesList.get(to[0]).add(to[1], replacedValue);
selectedGroup = -1;
selectedChild = -1;
if (oldTaskName != newTaskName){
replacedValue.setTaskName(newTaskName);
int progress1 = getProgress(oldTaskName);
activity.getDataBaseHelper().changeProgress(task1);
taskList.get(from[0]).setProgress(progress1);
int progress2 = getProgress(newTaskName);
taskList.get(to[0]).setProgress(progress2);
activity.getDataBaseHelper().changeProgress(task2);
}
}
notifyDataSetChanged();
activity.getDataBaseHelper().updatePositions(notesList.get(to[0]), activity);
}
in updatePositions(notesList.get(to[0]), activity) i`m write changes to db. It work fine.
public synchronized void updatePositions(ArrayList<Note> notes, Context context){
if (isDbClosed()){
init(context);
}
int taskName = notes.get(0).getTaskName();
db.delete(DataBaseHelper.NOTES_TABLE, " task = ? AND state = 0 ", new String[]{String.valueOf(taskName)});
for (Note note : notes){
addNote(note, context);
}
}
But, after this manipulation, i need to write another changes to dataBase (it happend if I check checkbox, and it write chanded state in asynckTask into DB) and its dont write. It work correctly if I do full reload of activity (database close and open). What I am I doing wrong? Thanks!
Aucun commentaire:
Enregistrer un commentaire