1

所以,标题几乎说明了一切。我有一个列表视图,其中填充了一个自定义光标适配器,该适配器显示来自数据库的数据。我有一个用于将项目添加到列表中的动画,它工作正常,但无法让用于从列表中删除项目的动画工作。我担心该项目正在从数据库中删除,并且在动画有机会执行之前正在刷新列表。感谢您对解决此问题的任何帮助。

动画代码

    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

    }
4

1 回答 1

1

我遇到了同样的问题。您应该removeChild(parentView, childView)Transition刷新ListView. 这可能不是最好的方法,但它确实有效。

顺便说一句,我会在Loader这里使用:http: //developer.android.com/guide/components/loaders.html

UPD:您需要在动画完成后运行其余代码(否则将被中断)。像这样的东西:

public void refreshNoteList(Cursor cursor) {
    transition.removeChild(ListView mNotesListView, View mNotesListView.getChildAt(int position);
    new Handler().postDelayed(new Runnable(){
        public void run() {
            mNoteAdapter.changeCursor(cursor);
            mNoteAdapter.notifyDataSetChanged();

            setNewNoteText(""); //clear the text
        }
    }, disappearAnim.getDuration());
}
于 2014-12-20T20:59:55.133 回答