Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detach ItemTouchHelper from RecyclerView

Tags:

I have a RecyclerView with a working ItemTouchHelper. Everything works great, but I am wondering if there is a way I can detach the ItemTouchHelper from the RecyclerView without re-creating the list? For fun, this is the code I'm using to attach:

ItemTouchHelper.Callback callback = new ItemTouchHelper.SimpleCallback(0, ItemTouchHelper.LEFT | ItemTouchHelper.RIGHT) {     ... }; mItemTouchHelper = new ItemTouchHelper(callback); mItemTouchHelper.attachToRecyclerView(mPasswordList); 

Ideally, I'd like to check a preference in say onResume() of the Activity this RecyclerView lives in and detach the ItemTouchHelper based on that.

like image 204
nverbeek Avatar asked Feb 11 '16 17:02

nverbeek


1 Answers

You can detach the ItemTouchHelper from the RecyclerView by setting recyclerview to null:

mItemTouchHelper.attachToRecyclerView(null); 
like image 108
Andy Cheng Avatar answered Sep 20 '22 02:09

Andy Cheng