Android的光标RecyclerView不上刷卡轻弹 [英] Android Cursor RecyclerView does a flick on swipe

查看:193
本文介绍了Android的光标RecyclerView不上刷卡轻弹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要实现我的看法回收物品滑动式

I want to implement swipeable items in my recycler view.

我使用了装载机填充( Github上的链接这里)的自定义回收适配器和对于刷卡定制的监听器(这里 Github上链接)。

I'm using a custom recycler adapter populated with a Loader (Github link here) and a custom listener for swipe (Github link here).

数据与SQLite的本地存储和一个过滤光标调用中检索。

Data is stored locally with a SQLite and retrieved with a call to a filtered Cursor.

我觉得我做得不对的实现,因为当我尝试刷的是,我回收项目得到闪现在很短的时间,然后消失,会发生什么。

I think I'm doing something wrong with the implementations, because what happens when I try to swipe is that my recycler item get like "flashed" for a very short time and then disappear.

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

Everything works fine except for this strange behavior.

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

This is my method for delete the item from the database:

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(位置)方法更快的事实,但我真的不知道这件事。

I think that this flash is due to the fact that the animation performs faster than the swipeItem(position) method, but I'm not really sure about it.

在这一点上,任何帮助将是非常非常AP preciated,先谢谢了。

At this point, any help would be very very appreciated, thanks in advance.

推荐答案

显然,我已经成功地找到解决这一点。
使用由费德里科庞氏在<提供的包装href=\"http://stackoverflow.com/questions/15468100/cursoradapter-backed-listview-delete-animation-flickers-on-delete\">this问题。

Apparently, I've managed to find a solution to this. Using the Wrapper provided by Federico Ponzi in this question.

在我刷卡监听器,我称之为的AsyncTask类,直接做的去除作业上的光标在后台,那么 onPostExecute 我称之为 getLoaderManager。 restartLoader(...);

In my swipe listener, I call an AsyncTask class which does the removing work directly on the cursor in background, then onPostExecute I call getLoaderManager.restartLoader(...);.

在此期间,我设置临时CursorWrapper展示我的新数据。
一旦完成AsyncTask的他的工作,getLoaderManager被调用在我的主要活动和我recyclerView得到新鲜的变压器与新的数据。

In the meantime, I set a temporary CursorWrapper to show my new data. As soon as the AsyncTask finish his work, getLoaderManager get called in my main activity and my recyclerView get the fresh adapter with the new data.

不知道,如果它是很清楚,我的英语没有帮助是肯定的。

Not sure if it's enough clear, my english doesn't help for sure.

这篇关于Android的光标RecyclerView不上刷卡轻弹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆