简体   繁体   English

从RecyclerView / ItemTouchHelper拖放后更新数据库

[英]Updating db after dragndrop from RecyclerView/ItemTouchHelper

Implemented drag'ndrop for RecyclerView via ItemTouchHelper, so user can change order of items by dragging them up or down. 通过ItemTouchHelper为RecyclerView实现了拖放,因此用户可以通过上下拖动来更改项目的顺序。

As by spec - the movement ends when ItemTouchHelper.Callback#clearView is called by android support library, so we need to update DB here (sqlite) and change order of dragged item and others (which were affected) - means ~a few requests to DB. 按照规范-当Android支持库调用ItemTouchHelper.Callback#clearView时,运动结束,因此我们需要在此处更新数据库(sqlite)并更改拖动项和其他项的顺序(受影响的)-意味着D B。

But as I see clearView is called from GUI thread we can't do it from there (a few requests can be quite heavy depending on DB indexes and number of affected items). 但是,正如我看到的,从GUI线程调用clearView我们无法从那里调用它(根据数据库索引和受影响项目的数量,一些请求可能非常繁重)。

So what are the best practices here? 那么,这里的最佳实践是什么? Or just triggering DB updates from clearView via android.os.AsyncTask ? 或者只是通过android.os.AsyncTaskclearView触发数据库更新?

最后,我通过android.os.AsyncTask :将所有数据库交互都移到了那里。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM