Delete group in Expandable List

后端 未结 2 1310
清歌不尽
清歌不尽 2020-12-10 09:47

I am trying to delete Group when selected in my Expandable List and having the list refreshed after the delete occurred.

I took the source code from

2条回答
  •  心在旅途
    2020-12-10 10:15

    Answer for the second question (Add rows to a child & datastructure)

    For the Datastructure:

    public class GroupItem {
     private String mItemText;
     private List mChildItems=new ArrayList();    
    
     public GroupItem(String itemText) {
      mItemText=itemText;
     }
    
     public String getItemText() {
      return mItemText;
     }
    
     public ChildItem getChild(int childPosition) {
      return mChildItems.get(childPosition);
     }
    
     public void addChild(ChildItem childItem) {
      return mChildItems.add(childItem)
     }
    
     public void removeChild(int childPosition) {
      return mChildItems.remove(childPosition);
     }
    
    }
    
    public class ChildItem {
     private String mItemText;
     public ChildItem(itemText) {
      mItemText=itemText;
     }
    
     public String getItemText() {
      return mItemText;
     }
    }
    

    Now to set it up you would do something like:

    List items = new ArrayList();
    
    GroupItem item1 = new GroupItem("This is group 1");
    item1.addChild(new ChildItem("This is a child item of group 1"));
    item1.addChild(new ChildItem("This is another child item of group 1"));
    

    and so on...

    Then, in the Adapter you would need to return the appropriate data.

    For your question concerning rows: In your Google example, they return a TextView. You can however make your own Layout with whatever content you like. For example:

    
    
    
    
    
    
    

    And then use this Layout in your Adapter. Instead of returning, say, a TextView, you'll just return this as a View:

    public View getChildView(int groupPosition, int childPosition, boolean isLastChild,
                View convertView, ViewGroup parent) {
    
    LayoutInflater mInflater = (LayoutInflater)mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View rowView = mInflater.inflate(YOUR XML FILE FROM ABOVE, null);
        ImageView rowIcon = (ImageView)rowView.findViewById(R.id.RowIcon);
        iconType.setBackgroundResource(AN IMAGE HERE);
        TextView rowText =(TextView)rowView.findViewById(R.id.RowTextView);
        textAddress.setText(items.get(groupPosition).getChild(childPosition));
    
        return rowView;
     }
    

    So, i think that should get you going.

    Also, please accept my answers if they satisfy you.

    Cheers.

提交回复
热议问题