Implementing FloatingGroupExpandableListView in a listview consisting 2 types of headers

前端 未结 2 1628
野趣味
野趣味 2021-01-15 18:53

I tried to implement FloatingGroupExpandableListView but I was unable to modify it according to my custom listview.

The below code implements 2 types of headers in t

相关标签:
2条回答
  • 2021-01-15 19:20

    try FloatingGroupExpandableListView

    I find this to be the best implementation. This use reflection to do the job. Just need to use android GroupExpandableListView and BaseExpandableListAdapter.

    List<ContentWrapper> items = new ArrayList<ContentWrapper>();
    ContentWrapper group;
    for (int i = 1; i <= 14; i++) {
      if (!(q.get(i).getA_name().trim().equals(q.get(i-1).getA_name().trim()))) {
        group = new ContentWrapper(q.get(i).getA_name(), null,null));
      }
      ContentWrapper item = new ContentWrapper(q.get(i).getAS_name(), q.get(i).getDesc_art(),null);
      if(!(q.get(i).getExtra()==null))
         item.setShowGraySeparator();//the gray separator should be merged with item view;
      items.add(item);
    }
    mAdapter.addGroup(group,items);
    

    public class CustomExpandableListAdapter extends BaseExpandableListAdapter {
    
        private List<ContentWrapper> mGroups = new ArrayList<ContentWrapper>();
        private List<List<ContentWrapper>> mData = new ArrayList<List<ContentWrapper>>();
    
        public void addGroup(ContentWrapper group,List<ContentWrapper> items) {
            mGroups.add(group);
            mData.add(items);
        }
    
        @Override
        public int getGroupCount() {
            // sticky header count
            return mGroups.size();
        }
    
        @Override
        public int getChildrenCount(int groupPosition) {
            // child count for each group at 'groupPosition'
            mData.get(groupPosition).size();
        }        
    
        @Override
        public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {
            //sticky header view at 'groupPosition'
            ContentWrapper header = mGroups.get(groupPosition);
            //show group view 
        }
    
        @Override
        public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent) {
           //child view at 'childPosition' for 'groupPosition'
           ContentWrapper item = mData.get(groupPosition).get(childPosition);
           // show item view
        }
    
    }
    
    0 讨论(0)
  • Take a look at this implementation: https://github.com/beworker/pinned-section-listview It requires your adapter to implement interface with only one method:

    public boolean isItemViewTypePinned(int viewType)
    

    So you could easily integrate this library into your code.

    0 讨论(0)
提交回复
热议问题