拖放后如何记住RecyclerVIew物品的位置

时间:2019-03-25 22:58:25

标签: android android-recyclerview drag-and-drop itemtouchhelper

我有recyclerVIew,其中实现了ItmeTouchHelper来拖放RecyclerVIew的项目,但未保存项目的位置

var itemTouch = ItemTouchHelper(object : 

    ItemTouchHelper.SimpleCallback(ItemTouchHelper.UP or ItemTouchHelper.DOWN,0){
                override fun onMove(recyclerView: RecyclerView?, source: RecyclerView.ViewHolder?, target: RecyclerView.ViewHolder?): Boolean {
                    var source = source?.adapterPosition
                    var target = target?.adapterPosition
                    Collections.swap(database.DairyData(),source!!,target!!)
                    adapter.notifyItemMoved(source,target)
                    return true

                }

                override fun onSwiped(viewHolder: RecyclerView.ViewHolder?, direction: Int) {

                }

            })
                    itemTouch.attachToRecyclerView(Dairy_recyclerView)

0 个答案:

没有答案