Pass Data between two different ViewHolder
Sample Demonstrates how to pass Data between two different ViewHolder which results in either cases.
This sample code contains 4 files :
Responsible for loading dummy data from data.json present inside assets folder.
Source can be REST API also depending on requirement.
Contains 2 RecyclerView
Responsible for loading parent views.
private OnClickParentHeader mListener;
public interface OnClickParentHeader {
void changeChildItems(List<CustomModel> items);
}
public MyCustomParentAdapter(Context ctx,
HashMap<String, String> hMapHeaderAndCount,
LinkedHashMap<String, List<CustomModel>> lstData,
OnClickParentHeader listener) {
this.mListener = listener;
this.ctx = ctx;
this.lstData = lstData;
this.hMapHeaderAndCount = hMapHeaderAndCount;
this.lstKey = getKeys();
}
OnClickParentHeader
CallBack Interface between Adapter & MainActivity.
HashMap
HashMap
LinkedHashMap
LinkedHashMap
Responsible for loading child views.
public interface ListenerCountCallback {
void notifyParentAdapter(int count);
}
public ChildAdapter(Context ctx,List<CustomModel> lstChild,ListenerCountCallback adapter) {
this.mListener = adapter;
this.lstChild = lstChild;
this.ctx = ctx;
}