0

I have a horizontal RecyclerView inside a ScrollView but none of the adapter methods are being triggered.

This is my fragment with the ScrollView:

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
   android:orientation="vertical" android:layout_width="match_parent"
   android:background="@color/white"
   android:layout_height="match_parent">

    <RelativeLayout
       android:layout_width="match_parent"
       android:layout_height="match_parent">

    <include layout="@layout/selector"
        android:layout_width="match_parent"
        android:layout_height="100dp"
        android:id="@+id/selector"/>

  .....
  .....

   </RelativeLayout>
</ScrollView>

This is my selector.xml layout:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
   android:orientation="vertical" android:layout_width="match_parent"
   android:layout_height="100dp"
   android:background="@color/green">

    <android.support.v7.widget.RecyclerView
       android:id="@+id/rv_kids"
       android:layout_width="match_parent"
       android:layout_height="100dp" />

</LinearLayout>

And here I'm setting the adapter to the RecyclerView:

selectorAdapter = new selectorAdapter(activity, kids);
rv_items.setLayoutManager(new LinearLayoutManager(activity, LinearLayoutManager.HORIZONTAL, false));
rv_items.setAdapter(selectorAdapter);
selectorAdapter.notifyDataSetChanged();

The thing is, the green background I've set to the selector shows up but none of the adapter methods are triggered and the RecyclerView doesn't inflate. What can I do differently?

Mallika Khullar
  • 1,725
  • 3
  • 22
  • 37

1 Answers1

0

You should use Nested Scrollview https://developer.android.com/reference/android/support/v4/widget/NestedScrollView.html instead. However you may need to write your own LayoutManager. Check out this SO Answer for more details

How to use RecyclerView inside NestedScrollView?

Community
  • 1
  • 1
Quick learner
  • 10,632
  • 4
  • 45
  • 55
  • Hey the custom LayoutManager was crashing at `View view = recycler.getViewForPosition(position)` even though I was binding the data with the list correctly and the adapter count was correct. But instead of debugging further, I think I'm gonna switch to using a LinearLayout and add views to it instead and make it behave like a RecylerView. – Mallika Khullar Nov 30 '16 at 08:50