title: How Make Recyclerview With Child Recyclerview in android
body: <p>I want to make something like Spotify home view with Retrofit but I cannot understand how to do it. please help him I am very confused. please help him these are my XML code look like these. First Is the Main Layout Recyclerview, Second Layout Is Recyclerview RowItem List and another one is innerItem row list. I want to get something like these how to get actual output like Spotify.
  I want to show these but they give me the same data but I have got different data with different arraylist.. then how to show different data.</p>
  
  <p><a href="https://i.stack.imgur.com/dWf7i.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/dWf7i.png" alt="enter image description here"></a></p>
  
  <p><a href="https://i.stack.imgur.com/IVMh6.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/IVMh6.png" alt="enter image description here"></a></p>
  
  <p><a href="https://i.stack.imgur.com/N1U3d.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/N1U3d.png" alt="enter image description here"></a></p>
  
  <p>Main Recyclerview.xml</p>
  
  <pre><code>            &lt;RelativeLayout
                  android:layout_width="match_parent"
                  android:layout_height="match_parent"
                  android:orientation="vertical"&gt;
  
                  &lt;android.support.v7.widget.RecyclerView
                      android:id="@+id/list_product"
                      android:layout_width="match_parent"
                      android:layout_height="match_parent" /&gt;
  
  
              &lt;/RelativeLayout&gt;
  
  RecyclerviewItem.xml
  
  &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:orientation="vertical"&gt;
  
      &lt;android.support.v7.widget.CardView
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:layout_margin="@dimen/_10sdp"&gt;
  
          &lt;LinearLayout
              android:layout_width="match_parent"
              android:layout_height="wrap_content"
              android:orientation="vertical"
              android:layout_margin="@dimen/_5sdp"&gt;
  
              &lt;TextView
                  android:id="@+id/tvCatName"
                  android:layout_width="match_parent"
                  android:layout_height="wrap_content"
                  android:padding="@dimen/_10sdp"
                  android:text="cat name"/&gt;
  
              &lt;android.support.v7.widget.RecyclerView
                  android:id="@+id/catProductList"
                  android:layout_width="match_parent"
                  android:layout_height="wrap_content"&gt;
              &lt;/android.support.v7.widget.RecyclerView&gt;
          &lt;/LinearLayout&gt;
      &lt;/android.support.v7.widget.CardView&gt;
  
  &lt;/LinearLayout&gt;
  
  Inneritem.xml
  
  &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      xmlns:app="http://schemas.android.com/apk/res-auto"
      android:orientation="vertical"&gt;
  
      &lt;android.support.v7.widget.CardView
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_margin="@dimen/_10sdp"&gt;
  
          &lt;LinearLayout
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:orientation="vertical"&gt;
  
              &lt;android.support.v7.widget.CardView
                  android:layout_width="@dimen/_160sdp"
                  android:layout_height="@dimen/_170sdp"
                  app:cardPreventCornerOverlap="false"&gt;
  
              &lt;ImageView
                  android:id="@+id/imgProduct"
                  android:layout_width="match_parent"
                  android:layout_height="match_parent"
                  android:src="@drawable/ic_bags"/&gt;
              &lt;/android.support.v7.widget.CardView&gt;
  
  
              &lt;TextView
                  android:id="@+id/tvProductName"
                  android:layout_width="wrap_content"
                  android:layout_height="wrap_content"
                  android:text="Yello New Shirt"
                  android:layout_gravity="center"
                  android:padding="@dimen/_5sdp"
                  android:textStyle="bold"
                  android:layout_marginTop="@dimen/_2sdp"
                  android:textSize="@dimen/_16ssp"
                  android:singleLine="true"/&gt;
  
              &lt;TextView
                  android:id="@+id/tvProductPrice"
                  android:layout_width="wrap_content"
                  android:layout_height="wrap_content"
                  android:text="15.00"
                  android:layout_gravity="center"
                  android:padding="@dimen/_5sdp"
                  android:textStyle="bold"
                  android:layout_marginTop="@dimen/_2sdp"
                  android:textSize="@dimen/_13ssp"
                  android:singleLine="true"/&gt;
  
          &lt;/LinearLayout&gt;
      &lt;/android.support.v7.widget.CardView&gt;
  
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p>My Code I don't know What is Problem</p>
  
  <pre><code>Data.java
  public class Data {
  
      String categoryName;
      ArrayList&lt;ProductsModel&gt; productsModels;
  
      public Data() {
      }
  
      public Data(String categoryName, ArrayList&lt;ProductsModel&gt; productsModels) {
          this.categoryName = categoryName;
          this.productsModels = productsModels;
      }
  
      public ArrayList&lt;ProductsModel&gt; getProductsModels() {
          return productsModels;
      }
  
      public void setProductsModels(ArrayList&lt;ProductsModel&gt; productsModels) {
          this.productsModels = productsModels;
      }
  
      public String getCategoryName() {
          return categoryName;
      }
  
      public void setCategoryName(String categoryName) {
          this.categoryName = categoryName;
      }
  }
  
  InCategoryProductAdapter.java
  
  public class InCategoryProductAdapter extends RecyclerView.Adapter&lt;InCategoryProductAdapter.ViewHolder&gt; {
  
      private Context context;
      private ArrayList&lt;Data&gt; dataArrayList;
      private RecyclerView.RecycledViewPool recycledViewPool;
  
      public InCategoryProductAdapter(Context context, ArrayList&lt;Data&gt; dataArrayList) {
          this.context = context;
          this.dataArrayList = dataArrayList;
  
          recycledViewPool = new RecyclerView.RecycledViewPool();
      }
  
      @NonNull
      @Override
      public ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
  
          View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.main_row_list,viewGroup,false);
          return new ViewHolder(view);
      }
  
      @Override
      public void onBindViewHolder(@NonNull ViewHolder viewHolder, int i) {
  
          viewHolder.tvCatName.setText(dataArrayList.get(i).getCategoryName());
          LinearLayoutManager manager = new LinearLayoutManager(context,LinearLayoutManager.HORIZONTAL,false);
          viewHolder.catProductList.setLayoutManager(manager);
  
          InnerItemAdapter innerItemAdapter = new InnerItemAdapter(context,dataArrayList.get(i).getProductsModels());
          viewHolder.catProductList.setAdapter(innerItemAdapter);
  
      }
  
      @Override
      public int getItemCount() {
          return dataArrayList.size();
  
      }
  
      class ViewHolder extends RecyclerView.ViewHolder{
  
          TextView tvCatName;
          RecyclerView catProductList;
  
          public ViewHolder(@NonNull View itemView) {
              super(itemView);
  
              tvCatName = itemView.findViewById(R.id.tvCatName);
              catProductList = itemView.findViewById(R.id.catProductList);
          }
      }
  }
  
  Fragment.java
  
  /*set Catgeory  Api if get department ID*/
      private void setCategory(int dept_id) {
          models = new ArrayList&lt;&gt;();
          RetrofitInterface retrofitInterface = RetrfitClient.getRetrofitClient().create(RetrofitInterface.class);
          Call&lt;ArrayList&lt;CategoryModel&gt;&gt; arrayListCall = retrofitInterface.Category_Call(dept_id);
          arrayListCall.enqueue(new Callback&lt;ArrayList&lt;CategoryModel&gt;&gt;() {
              @Override
              public void onResponse(Call&lt;ArrayList&lt;CategoryModel&gt;&gt; call, Response&lt;ArrayList&lt;CategoryModel&gt;&gt; response) {
  
                  models = response.body();
                  for (int i = 0; i &lt; models.size(); i++) {
                      catId = models.get(i).getCategory_id();
                      setCategoryProduct(catId, models);
                  }
                  //Log.d("ModelsSize", "" + models.size());
              }
  
              @Override
              public void onFailure(Call&lt;ArrayList&lt;CategoryModel&gt;&gt; call, Throwable t) {
  
                  Toast.makeText(getActivity(), t.toString(), Toast.LENGTH_SHORT).show();
              }
          });
      }
  
      /*get category wise product From Server*/
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/ykISO.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ykISO.png" alt="enter image description here"></a>
     private void setCategoryProduct(int catId, final ArrayList categoryModels, final String catName) {</p>
  
  <pre><code>Log.d("getSingleCat", "" + catId);
  
  productsModels = new ArrayList&lt;&gt;();
  RetrofitInterface anInterface = RetrfitClient.getRetrofitClient().create(RetrofitInterface.class);
  Call&lt;ProductInCategoryResponse&gt; inCategoryResponseCall = anInterface.IN_CATEGORY_RESPONSE_CALL(catId, 1);
  inCategoryResponseCall.enqueue(new Callback&lt;ProductInCategoryResponse&gt;() {
      @Override
      public void onResponse(Call&lt;ProductInCategoryResponse&gt; call, Response&lt;ProductInCategoryResponse&gt; response) {
  
          productsModels = response.body().getRows();
          Log.d("productCat", "" + productsModels.size());
  
          data.setCategoryName(catName);
          data.setProductsModels(productsModels);
  
          dataArrayList = new ArrayList&lt;&gt;();
  
  
  
          HashMap&lt;String,ArrayList&lt;ProductsModel&gt;&gt; listHashMap = new HashMap&lt;String, ArrayList&lt;ProductsModel&gt;&gt;();
          for (int j=0;j&lt;categoryModels.size();j++){
              dataArrayList.add(data);
              listHashMap.put(categoryModels.get(j).getName(), productsModels);
              Log.d("ListMap",""+listHashMap.put(categoryModels.get(j).getName(),productsModels));
          }
  
          Log.d("CatName",""+catName);
  
          /*Gson gson  = new Gson();
          String pList = gson.toJson(productsModels);*/
  
  
          LinearLayoutManager manager = new LinearLayoutManager(getActivity());
          mainRecyclerView.setLayoutManager(manager);
  
          InCategoryProductAdapter inCategoryProductAdapter = new InCategoryProductAdapter(getActivity(), dataArrayList);
          mainRecyclerView.setAdapter(inCategoryProductAdapter);
  
          /*
          Log.d("DataArray", "" + dataArrayList.size());
          Log.d("GetCat", "" + data.getCategoryName());*/
          // Log.d("DataList",""+dataArrayList.get(i).getCategoryName() + " :"+ dataArrayList.get(i).getProductsModels());
  
      }
  
      @Override
      public void onFailure(Call&lt;ProductInCategoryResponse&gt; call, Throwable t) {
  
          Toast.makeText(getActivity(), t.toString(), Toast.LENGTH_SHORT).show();
      }
  });
  </code></pre>
  
  <p>}</p>