In my app I have a (primary) RecyclerView that shows CardViews. In each CardView displayed there is in turn a (secondary) RecyclerView, which also displays CardViews. (Nested RecyclerView) These (secondary) RecyclerViews are set up in the onBindViewHolder method in the adapter of the primary RecyclerView, where I also allow swiping the CardViews in the (secondary) RecyclerView using ItemTouchHelper.
public void onBindViewHolder( RkTageViewHolder holder, int position ) {
...
LinearLayoutManager layoutManager = new LinearLayoutManager( holder.rvAbschnitte.getContext(), LinearLayoutManager.VERTICAL, false);
current.setRkAbschnitte(m_rkAbschnittDao.getRkAbschnittListe(current.getReiseID()));
layoutManager.setInitialPrefetchItemCount(current.getRkAbschnitte().size());
RkAbschnitteAdapter rkAbschnitteAdapter = new rkAbschnitteAdapter(current.getRkAbschnitte());
holder.rvAbschnitte.setLayoutManager(layoutManager);
holder.rvAbschnitte.setAdapter(rkAbschnitteAdapter);
...
new ItemTouchHelper(new ItemTouchHelper.SimpleCallback(0, ItemTouchHelper.LEFT | ItemTouchHelper.RIGHT) {
@Override
public boolean onMove(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, RecyclerView.ViewHolder target) {
return false;
}
@Override
public void onSwiped(RecyclerView.ViewHolder viewHolder, int direction) {
Toast.makeText(holder.rvAbschnitte.getContext(), "Löschen aktuell nicht möglich...", Toast.LENGTH_SHORT).show();
}
}).attachToRecyclerView(holder.rvAbschnitte);
...
}
Everything works perfectly until I also allow swiping of the CardViews in the primary RecyclerView. No matter where I swipe, only the CardView is moved in the primary RecyclerView.
If I only allow swiping to the right in the primary RecyclerView and to swipe to the left in the secondary, it works. As soon as I allow swiping in the same direction in both RecyclerViews, only the cardViews in the primary RecyclerView are moved.
Is there a way to tell the primary RecyclerView that it will pass the swipe command on to its child RecyclerView when the swipe is carried out there?
Many thanks
Uwe