So, the title pretty much says it all. I have a listview which is populated with a custom cursor adapter which displays data from a database. I have an animation for adding items to the list which works fine but am having trouble getting the animation for deleting items from the list to work. I fear that the item is being deleted from the database and the list is being refreshed before the animation has a chance to execute. I appreciate any help with fixing this issue.
Animation code
LayoutTransition transition = new LayoutTransition();
Animator appearAnim = ObjectAnimator.ofFloat(null, "rotationX", 90f, 0f)
.setDuration(android.R.integer.config_shortAnimTime);
Animator disappearAnim = ObjectAnimator.ofFloat(null, "alpha", 1f, 0f)
.setDuration(android.R.integer.config_longAnimTime);
transition.setAnimator(LayoutTransition.APPEARING, appearAnim);
transition.setAnimator(LayoutTransition.DISAPPEARING, disappearAnim);
mNotesListView.setLayoutTransition(transition);
The delete note method
@Override
public void deleteNote(final String noteId) {
new Thread() {
@Override
public void run() {
super.run();
mNotesTable.deleteNote(mDb, noteId);
int notebookNumber = mNoteBookFragment.getNotebookNumber();
final Cursor cursor = mNotesTable.notesQuery(mDb, notebookNumber);
runOnUiThread(new Runnable() {
@Override
public void run() {
mNoteBookFragment.refreshNoteList(cursor);
Toast.makeText(BlocNotes.this,
getString(R.string.delete_note_toast), Toast.LENGTH_LONG).show();
}
});
}
}.start();
}
and refreshing the list
public void refreshNoteList(Cursor cursor) {
mNoteAdapter.changeCursor(cursor);
mNoteAdapter.notifyDataSetChanged();
setNewNoteText(""); //clear the text
}
Edited Refresh Method
public void refreshNoteList(Cursor cursor) {
mTransition.removeChild(mNoteAdapter.getParent(), mNoteAdapter.getView());
mNoteAdapter.changeCursor(cursor);
mNoteAdapter.notifyDataSetChanged();
setNewNoteText(""); //clear the text
}