2

I have two RecyclerView in my Fragment.

 <LinearLayout                  
             android:layout_width="match_parent"
             android:layout_height="match_parent" 
             android:orientation="vertical"
             android:background="#E6E6E6">  
<RelativeLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" >
      <TextView
        android:id="@+id/textview"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:textSize="20sp"
        android:textColor="#000"
        android:paddingBottom="8dp"
        android:paddingTop="8dp"
        android:gravity="left"
        android:text="Trending"
        />
    <android.support.v7.widget.RecyclerView
    android:id="@+id/recycler_view"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:scrollbars="none"
    android:layout_below="@+id/textview"
   />

    <TextView
        android:id="@+id/popular_textview"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:textSize="20sp"
        android:textColor="#000"
        android:paddingBottom="8dp"
        android:paddingTop="8dp"
        android:gravity="left"
        android:text="Popular"
        android:layout_below="@+id/recycler_view"
        android:layout_marginTop="200dip"
        />
    <android.support.v7.widget.RecyclerView
    android:id="@+id/popular_recycler_view"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:scrollbars="none" 
    android:layout_below="@+id/popular_textview"/> 
 </RelativeLayout>

But it's only first RecyclerView is working . second one is not visible . My Fragment code is like this :

private void populatRecyclerView(ArrayList<HashMap<String, String>> imageList) {

    ArrayList<Data_Model> arrayList = new ArrayList<>();
    for (int i = 0; i < imageList.size(); i++) {
        HashMap<String, String> vector = imageList.get(i);
        category = vector.get("deal_category");
        if (category.equalsIgnoreCase("17")) {
            String imageurl = vector.get("deal_thumbnail");
            String title = vector.get("title");
            Uri uri = Uri.parse(imageurl);
            String filename = uri.getLastPathSegment();
            arrayList.add(new Data_Model(title, filename));
            RecyclerView_Adapter adapter = new RecyclerView_Adapter(getActivity(), arrayList);
            recyclerView.setAdapter(adapter);// first set adapter on recyclerview
            adapter.notifyDataSetChanged();// Notify the adapter
        } else {
            String imageurl = vector.get("deal_thumbnail");
            String title = vector.get("title");
            Uri uri = Uri.parse(imageurl);
            String filename = uri.getLastPathSegment();
            arrayList.add(new Data_Model(title, filename));

            RecyclerView_Popular_Adapter popular_adapter = new RecyclerView_Popular_Adapter(getActivity(), arrayList);
            popular_recyclerView.setAdapter(popular_adapter);// second set adapter on recyclerview
            popular_adapter.notifyDataSetChanged();// Notify the adapter
        }
    }
}

Even second TextView is also not appearing.I have specified first and second adapter in comment. So how make second RecyclerView visible too?

Asif Patel
  • 1,744
  • 1
  • 20
  • 27
Mhandroid
  • 219
  • 3
  • 13

1 Answers1

1

You cannot use layout_weight on childs of RelativeLayout . Your parent views should be under the LinearLayout like below;

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

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

        <TextView
            android:id="@+id/textview"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:gravity="left"
            android:paddingBottom="8dp"
            android:paddingTop="8dp"
            android:text="Trending"
            android:textColor="#000"
            android:textSize="20sp" />

        <android.support.v7.widget.RecyclerView
            android:id="@+id/recycler_view"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_below="@+id/textview"
            android:scrollbars="none" />

    </RelativeLayout>

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

        <TextView
            android:id="@+id/popular_textview"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:gravity="left"
            android:paddingBottom="8dp"
            android:paddingTop="8dp"
            android:text="Popular"
            android:textColor="#000"
            android:textSize="20sp" />

        <android.support.v7.widget.RecyclerView
            android:id="@+id/popular_recycler_view"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_below="@+id/popular_textview"
            android:scrollbars="none" />

    </RelativeLayout>

</LinearLayout>

enter image description here

Hope it helps!

oyenigun
  • 587
  • 6
  • 15
  • Yeah i tried by removing layout_weight still its not working. – Mhandroid Feb 02 '17 at 05:51
  • its not enough, you should seperate your RecylerViews by group and set layout_weight for this groups parent. – oyenigun Feb 02 '17 at 06:14
  • One more problem I am facing now . This view is not scrollable .I tried using but still not working. Can u help me please ? – Mhandroid Feb 02 '17 at 08:53
  • 1
    If it works, you should approve and complete this post. For one more problem, you should look this post; http://stackoverflow.com/questions/16515879/multiple-listviews-inside-a-scrollview – oyenigun Feb 02 '17 at 09:10
  • This link solution is not working for me .I have posted seperate question for scroll. – Mhandroid Feb 02 '17 at 09:27