项目作者: jay5727

项目描述 :
Pass Data between two different ViewHolder
高级语言: Java
项目地址: git://github.com/jay5727/ViewHolderPassData.git
创建时间: 2018-09-13T18:05:53Z
项目社区:https://github.com/jay5727/ViewHolderPassData

开源协议:

下载


ViewHolderPassData

Sample Demonstrates how to pass Data between two different ViewHolder which results in either cases.

  • Notify from one adapter to another that something has changed.
  • Pass result from second adapter to first adapter.

This sample code contains 4 files :

  • MyCustomParentAdapter
  • ChildAdapter
  • MainActivity
  • CustomModel

MainActivity

Responsible for loading dummy data from data.json present inside assets folder.
Source can be REST API also depending on requirement.
Contains 2 RecyclerView

MyCustomParentAdapter

Responsible for loading parent views.

  1. private OnClickParentHeader mListener;
  2. public interface OnClickParentHeader {
  3. void changeChildItems(List<CustomModel> items);
  4. }
  5. public MyCustomParentAdapter(Context ctx,
  6. HashMap<String, String> hMapHeaderAndCount,
  7. LinkedHashMap<String, List<CustomModel>> lstData,
  8. OnClickParentHeader listener) {
  9. this.mListener = listener;
  10. this.ctx = ctx;
  11. this.lstData = lstData;
  12. this.hMapHeaderAndCount = hMapHeaderAndCount;
  13. this.lstKey = getKeys();
  14. }
  • OnClickParentHeader

    CallBack Interface between Adapter & MainActivity.

  • HashMap hMapHeaderAndCount

    HashMap where K is Key (Title) displayed in 1st list on left side ,V is the value which will maintain the count of items selected in 2nd list.

  • LinkedHashMap> lstData

    LinkedHashMap where K is Key (Title) displayed in 1st list on left side, V is the value in this case List

ChildAdapter

Responsible for loading child views.

  1. public interface ListenerCountCallback {
  2. void notifyParentAdapter(int count);
  3. }
  4. public ChildAdapter(Context ctx,List<CustomModel> lstChild,ListenerCountCallback adapter) {
  5. this.mListener = adapter;
  6. this.lstChild = lstChild;
  7. this.ctx = ctx;
  8. }