Android 光标 RecyclerView 在滑动时轻弹

Android Cursor RecyclerView does a flick on swipe

我想在我的回收站视图中实现可滑动的项目。

我正在使用装有加载器 (Github link here) and a custom listener for swipe (Github link here) 的自定义回收器适配器。

数据使用 SQLite 在本地存储,并通过调用过滤的 Cursor 进行检索。

我认为我在实施方面做错了,因为当我尝试滑动时发生的事情是我的回收器项目在很短的时间内变得像 "flashed" 然后消失。

除了这种奇怪的行为外,一切正常。

这是我从数据库中删除项目的方法:

public void swipeItem(int position) {
    mDatabase.open();
    String cursor_string = recyclerFilter.getText().toString();
    final Cursor filterCursor = mDatabase.fetchVisible(cursor_string);
    filterCursor.moveToPosition(position);
    int pID = filterCursor.getColumnIndex("_id");
    final String iD = filterCursor.getString(pID);
    mDatabase.deleteItem(iD);

    getLoaderManager().restartLoader(MAIN_LOADER_ID, null, mCallbacks);
}

我认为这个闪光是由于动画执行速度比 swipeItem(position) 方法快,但我不太确定。

此时,非常感谢任何帮助,在此先感谢。

显然,我已经找到了解决方法。 使用 Federico Ponzi 在 this question.

中提供的包装器

在我的滑动侦听器中,我调用了一个 AsyncTask class,它在后台直接在光标上执行删除工作,然后 onPostExecute 我调用 getLoaderManager.restartLoader(...);

同时,我设置了一个临时的 CursorWrapper 来显示我的新数据。 一旦 AsyncTask 完成他的工作,getLoaderManager 就会在我的 main activity 中被调用,我的 recyclerView 会得到带有新数据的新适配器。

不确定是否足够清楚,我的英语肯定帮不​​上忙。