How to recycle adapter in another recycleview adapter?

I have a RecyclerView . It has its own layout, and inside the custom layout is another RecyclerView . When I notify the recycler that the item has been deleted, my resizer main view is updated, but my custom view in the view mode does not receive notifications.

  SwipeDismissRecyclerViewTouchListener listener = new SwipeDismissRecyclerViewTouchListener.Builder( recyclerView, new SwipeDismissRecyclerViewTouchListener.DismissCallbacks() { @Override public boolean canDismiss(int position) { return true; } @Override public void onDismiss(View view) { // Do what you want when dismiss int id = recyclerView.getChildAdapterPosition(view); databaseHelper.deleteSingleItem(cartAdapter.cartItemName.get(id)); Log.e(TAG, "onDismiss: " + subdata.get(id) + " " + data.get(id)); subdataprice.remove(id); subdata.remove(id); addonlist.remove(id); price.remove(id); data.remove(id); cartAdapter.notifyItemRemoved(id); Log.e(TAG, data.size() + " onDismiss: size " + subdata.size()); totalPriceTextView.setText(String.valueOf(getTotal())); cartAdapter.updateRecycler(); } }) .setIsVertical(false) .setItemClickCallback(new SwipeDismissRecyclerViewTouchListener.OnItemClickCallBack() { @Override public void onClick(int i) { // Toast.makeText(getBaseContext(), String.format("Delete item"), Toast.LENGTH_LONG).show(); } }) .create(); recyclerView.setOnTouchListener(listener); 

This is the RecyclerView removal code for removal. In my cart adapter I took another type of disposal. Any idea how to notify about adaptation if any data is removed from view mode.

My class onBindViewHolder

  @Override public void onBindViewHolder(CustomViewHolder holder, int position) { try { holder.itemName.setText(String.format("%s", cartItemName.get(position))); holder.itemPrice.setText(String.format("Β£ %s", cartItemPrice.get(position))); AddonRecycleviewAdapter recycleViewAdapter = new AddonRecycleviewAdapter(context, listsubdata.get(position), listsubprice.get(position), listsubAddon.get(position)); holder.addon_recycleview.setHasFixedSize(true); holder.addon_recycleview.setLayoutManager(new LinearLayoutManager(context, LinearLayoutManager.VERTICAL, false)); holder.addon_recycleview.setAdapter(recycleViewAdapter); } catch (Exception e) { e.printStackTrace(); } } 

Parent recycleview

  <android.support.v7.widget.RecyclerView android:id="@+id/cartRecyclerView" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginBottom="2dp" android:clipToPadding="false" android:padding="@dimen/item_gallery_padding" app:layout_behavior="@string/appbar_scrolling_view_behavior" /> 

Baby for kids

 <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal"> <ImageButton android:visibility="invisible" android:id="@+id/btnremove" android:layout_width="wrap_content" android:layout_height="match_parent" android:layout_margin="@dimen/standard_padding_small" android:background="@null" android:src="@drawable/ic_action_action_search" android:text="Remove" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_margin="@dimen/standard_padding_small" android:gravity="center_vertical" android:padding="8dp" android:text="+" /> <TextView android:id="@+id/addonNameTextView" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_margin="@dimen/standard_padding_small" android:layout_weight="1" android:ellipsize="end" android:gravity="center_vertical" android:maxLines="1" android:padding="8dp" android:text="9 inch Pizza" android:textAppearance="?android:attr/textAppearanceSmall" android:textColor="@color/secondary_text" /> <TextView android:id="@+id/addOnPriceTextView" android:layout_width="wrap_content" android:layout_height="match_parent" android:layout_margin="@dimen/standard_padding_small" android:gravity="center_vertical" android:maxLines="1" android:text="Β£3.15" android:padding="8dp" android:textAppearance="?android:attr/textAppearanceSmall" android:textColor="@color/primary_text" /> </LinearLayout> 
+8
android android-recyclerview android-adapter notifydatasetchanged
source share
3 answers

finally, I got my answer today, in another way I just call the adapter in synchronized

 synchronized(recyclerview){ recycleViewAdapter = new AddonRecycleviewAdapter(context, listsubdata.get(position), listsubprice.get(position), listsubAddon.get(position)); holder.addon_recycleview.setHasFixedSize(true); holder.addon_recycleview.setLayoutManager(new LinearLayoutManager(context, LinearLayoutManager.VERTICAL, false)); holder.addon_recycleview.setAdapter(recycleViewAdapter); } 
0
source share

Well, firstly, why do you need one recycler view in another? It is usually solved using an extensible form of recycler. Here is a good tutorial.

Secondly, I see this line cartAdapter.notifyItemRemoved(id); Where is the notification for the second recycler? Do you have a link to it? You must call notifyDataSetChanged() for this!

AND HE IS MY GOD, SUCH MANY ANONYMOUS CLASSES! I don’t even understand what is going on in your code! This is just incomprehensible. Get rid of it, seriously.

+1
source share

Try:

  @Override public void onBindViewHolder(CustomViewHolder holder, int position) { try { holder.itemName.setText(String.format("%s", cartItemName.get(position))); holder.itemPrice.setText(String.format("Β£ %s", cartItemPrice.get(position))); AddonRecycleviewAdapter recycleViewAdapter = new AddonRecycleviewAdapter(context); holder.addon_recycleview.setHasFixedSize(true); holder.addon_recycleview.setLayoutManager(new LinearLayoutManager(context, LinearLayoutManager.VERTICAL, false)); //Create a setter method in AddonRecycleviewAdapter adapter holder.addon_recycleview.setLists(listsubdata.get(position), listsubprice.get(position), listsubAddon.get(position)); holder.addon_recycleview.setAdapter(recycleViewAdapter); } catch (Exception e) { e.printStackTrace(); } } 

And in your setter do the following:

 //set list of items from ParentAdapter in your AddonRecycleviewAdapter adapter public void setLists(List<T> l1,List<T> l2,List<T> l3) { //Set You list as field variable here this.l1 = l1; this.l2 = l2; this.l3 = l3; this.notifyDataSetChanged(); } 
0
source share

All Articles