所以,标题几乎说明了一切。我有一个列表视图,其中填充了一个自定义光标适配器,该适配器显示来自数据库的数据。我有一个用于将项目添加到列表中的动画,它工作正常,但无法让用于从列表中删除项目的动画工作。我担心该项目正在从数据库中删除,并且在动画有机会执行之前正在刷新列表。感谢您对解决此问题的任何帮助。
动画代码
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);
删除笔记方法
@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();
}
并刷新列表
public void refreshNoteList(Cursor cursor) {
mNoteAdapter.changeCursor(cursor);
mNoteAdapter.notifyDataSetChanged();
setNewNoteText(""); //clear the text
}
编辑刷新方法
public void refreshNoteList(Cursor cursor) {
mTransition.removeChild(mNoteAdapter.getParent(), mNoteAdapter.getView());
mNoteAdapter.changeCursor(cursor);
mNoteAdapter.notifyDataSetChanged();
setNewNoteText(""); //clear the text
}