Search code examples
androidexpandablelistview

How to hide expandableListView group name when it is open


I have this structure in DrawerList:

  • more...
  • -object
  • -object
  • -...hide

I need hide "more..." when it is open.

Do it on this segment:

public class CategoryItemsAdapter extends BaseExpandableListAdapter {
...
public View getChildView(int groupPosition, int childPosition, boolean isExpanded, View view,
                         ViewGroup parent) {
    Link child = (Link) getChild(groupPosition, childPosition);
    LinksGroup group = (LinksGroup) getGroup(groupPosition);

    if (view == null) {
        LayoutInflater infalInflater = (LayoutInflater) context.getSystemService(context.LAYOUT_INFLATER_SERVICE);
        view = infalInflater.inflate(R.layout.category_item_counter, null);
    }
    TextView tv = (TextView) view.findViewById(R.id.title);
    tv.setText(child.getName().toString());

    if(isExpanded) {
    }
    else {
    }


    return view;
}

public View getGroupView(int groupPosition, boolean isLastChild, View view,
                         ViewGroup parent) {
    LinksGroup group = (LinksGroup) getGroup(groupPosition);

    String groupTitle = getGroup(groupPosition).toString();
    View viewGroup = new FrameLayout(context);

    if (view == null) {
        LayoutInflater inf = (LayoutInflater) context.getSystemService(context.LAYOUT_INFLATER_SERVICE);
        view = inf.inflate(R.layout.category_item_counter, null);
    }
    TextView tv = (TextView) view.findViewById(R.id.title);

    final float scale = context.getResources().getDisplayMetrics().density;
    int space = (int) (20 * scale + 0.5f);
    int item = (int) (40 * scale + 0.5f);

    if(group.getName() == null) {
        tv.setBackgroundColor(Color.DKGRAY);
        tv.setHeight(space);
        tv.setText("");
    }
    else {
        tv.setBackgroundColor(Color.WHITE);
        tv.setHeight(item);
        tv.setText(group.getName());
    }

    return view;
}
...
}

or i can do this on OnGroupClickListener?

I think for a long time. Need help.


Solution

  • Ok, I'm just added this:

     if(isExpanded) {
       tv.setHeight(0);
       return view;
     }
    

    to

    public View getGroupView(int groupPosition, boolean isExpanded, View view,
                             ViewGroup parent)