I have a really basic concept and it’s probably a really easy solution that I am missing.
I basically have a
recyclerView inside a
recyclerView. It works perfectly and everything is smooth.
I recently decided to add a swipe to delete to the
recyclerViews. The parent one (the outer most) works perfectly. However, when I try to do the exact same thing inside the parent
recyclerView's (for the child) adapter it returns the wrong adapter (it returns the parent’s adapter).
I think this is happening because the swipe is being detected on the parent before the child (since technically the child is part of the parent), is there a way to disable the swipe detection for the parent
recyclerView if it’s touching a child
recyclerView? For example, in the parent I have a textView acting as a header and then the
recyclerView right below it. Is it possible to only have the header (the
textView act as the swipe and then the rest will go through to the child?
I followed this tutorial (https://www.androidhive.info/2017/09/android-recyclerview-swipe-delete-undo-using-itemtouchhelper/) subtracting the JSON and just hard coding the data for simplicity and adding a
recyclerView inside the
adapter and having another adapter just for a
textView (content to make up the child’s cells).
A very bizarre thing happens – when I disable the parent’s swipe to delete entirely, only 1 random section works for the child. I could not find a pattern on why.
Basically to recap when I am calling my
ItemTouchHelper class’s methods, the
viewHolder is always the parent’s adapter instead of the child because the swipe is being detected on the entire parent instead of moving through to the child’s
recyclerView; is there a way to prevent or force it to go through to the child while keeping all other elements (like a
textView header) on the parent?
After a long and hard time I managed to figure it out.
Very simple for anyone else struggling:
You have two separate adapters (1 for your header + recyclerItemView) and one for your items.
In your header one (calling it section) you an interface that will watch for onSwipe and OnDrag events being called from your item’s adapter.
I will post full code if people are interested. I think this approach is much better than having 1 list and some delimiter to determine which viewType to use.