Implemented drag'ndrop for RecyclerView via ItemTouchHelper, so user can change order of items by dragging them up or down.
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.
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).
So what are the best practices here? Or just triggering DB updates from clearView
via android.os.AsyncTask
?
最后,我通过android.os.AsyncTask
:将所有数据库交互都移到了那里。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.