我有 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)