Android RecyclerView ItemTouchHelper revert swipe and restore view holder

前端 未结 8 761
栀梦
栀梦 2020-12-04 19:09

Is there a way to revert a swipe action and restore the view holder to its initial position after the swipe is completed and onSwiped is called

8条回答
  •  情歌与酒
    2020-12-04 19:52

    With the latest anndroidX packages I still have this issue, so I needed to adjust @jimmy0251 solution a bit to reset the item correctly (his solution would only work for the first swipe).

     override fun onSwiped(viewHolder: RecyclerView.ViewHolder, direction: Int) {
                    clipAdapter.notifyItemChanged(viewHolder.adapterPosition)
                    itemTouchHelper.startSwipe(viewHolder)
                }
    

    Note that startSwipe() resets the item's recovery animations correctly.

提交回复
热议问题