is it possible to put a recyclerview into another with data from retrofit 2?

Firstly, You should change your UrunAdapter.getItemCount() to return urun.size() instead of urunListeSize. It will be easy to synchronize.

You need to call the notifyDataSetChanged() in the callback. Instead of passing categories.getId(), just pass the categories object. Also you should pass the item adapter. The retrofit, once it retrieves the data, will update categories.urunListeList and notify through the adapter that the dataset changed.

onBindViewHolder code

@Override
public void onBindViewHolder(@NonNull CategoryAdapterViewHolder holder, int position) {
    categories = categoriesList.get(position);

    categories.setUrunListeList(new ArrayList<UrunListe>());

    LinearLayoutManager linearLayoutManager = new LinearLayoutManager(context);
    linearLayoutManager.setOrientation(RecyclerView.VERTICAL);
    holder.rvSubCategories.setLayoutManager(linearLayoutManager);
    holder.rvSubCategories.hasFixedSize();
    rvUrunAdapter = new UrunAdapter(context, categories.getUrunListeList(), this::onSelectedUrun, urunListes.size());

    holder.txtHeader.setText(categories.getCategoryName());
    holder.rvSubCategories.setAdapter(rvUrunAdapter);

    //rvUrunAdapter.notifyDataSetChanged();
    //This is not required.

    createSubCategories(context, categories, rvUrunAdapter, position);

}

Change the header of the ‘createSubCategories’ method accordingly.

private void createSubCategories(Context context1, Categories catId, UrunAdapter urunAdapter, int position)

Finally modify the onResponse code. Here you should not assign the callback result to categories.urunListeList. Instead you should append.

@Override

        public void onResponse(Call<UrunListe[]> call, Response<UrunListe[]> response) {

            if (response.isSuccessful()){
                 List<UrunListe> tempList = Arrays.asList(response.body());
                  //If you are planning to refresh this data, you should clear it first.
                urunListeList.clear();
                for(UrunListe urunListe:templist)                    
                    categories.urunListeList.add(urunListe);

                Log.d("TAG apiCall", response.message());
                Log.d("TAG apiCall", "OK ürünler");

               urunAdapter.notifyDataSetChanged();

            }
        }

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top