Search code examples
androidlistviewandroid-listviewandroid-recyclerview

Nested scrolling : ListView inside a RecyclerView


I'm building an android app, and right now it has a main recycler view (populated with items, which are layed out w/ item.xml), and inside every item.xml, there is a listView.

How can I make scrolling work in this listview, because right now the app just listens to the scrolling of the recycler view ?

I've tried the line below, but it doesn't work :

 android:nestedScrollingEnabled="true"

Thank you so much for you help :) !


Solution

  • I solved like this :

      mRecyclerView.addOnItemTouchListener(new RecyclerView.OnItemTouchListener() {
                @Override
                public boolean onInterceptTouchEvent(RecyclerView rv, MotionEvent e) {
                    if(rv.getChildCount() > 0) {
                        View childView = rv.findChildViewUnder(e.getX(), e.getY());
                        if(rv.getChildPosition(childView) == [listview position]) {
                            int action = e.getAction();
                            switch (action) {
                                case MotionEvent.ACTION_DOWN:
                                    rv.requestDisallowInterceptTouchEvent(true);
                            }
                        }
                    }
    
                    return false;
                }
    
                @Override
                public void onTouchEvent(RecyclerView rv, MotionEvent e) {
    
                }
            });