Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to hide group in ExpandableListView in android

Tags:

android

In ExpandableListView if I only have one group. I want to hide that group, only the group's data show that. Please help me

enter image description here

like image 964
Nhu Nguyen Avatar asked Dec 12 '11 15:12

Nhu Nguyen


4 Answers

I had the same problem and this solveed my issue. In your Listview's adapter add the following to the getGroupView.

if (groupPosition == 0) {
     convertView = layoutInflater.inflate(R.layout.blank_layout, null);

} else {
    convertView = layoutInflater.inflate(R.layout.group_indicator_cell,null);
}

This will blank the 0th groupof the list.

Where blank layout is a layout with some view inside having layout_height=0dp. It works!

like image 142
Ajith Memana Avatar answered Nov 14 '22 04:11

Ajith Memana


1) Hide the Group indicator with:

android:groupIndicator="@android:color/transparent"

2) return an empty FrameLayout for the groups you want to be empty like this:

    @Override
public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {

    //By default the group is hidden
    View view = new FrameLayout(context);

    String groupTitle = getGroup(groupPosition).toString();

    //in case there's more than one group and the group title is not empty then show a TextView within the group bar
    if(getGroupCount() > 1 && !groupTitle.isEmpty()) {

        view = getGenericView();
        ((TextView)view).setText(groupTitle);
    }

    return view;

}

3) Call expandGroup for the groups you are not showing the group bar:

expandableListView.expandGroup(GROUP_ID);

4) If you want to show a group indicator you have to add an ImageView programmatically from the getGroupView method. Check this blog post for more info on hiding/showing group indicator: Hiding group indicator for empty groups

like image 22
Giorgio Avatar answered Nov 14 '22 05:11

Giorgio


Instead of returning a empty layout, I travel through all children in the layout and call view.setVisibility(View.Gone) when there is no data.

@Override
public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {

    LinearLayout lo;

    if (convertView != null) {
        lo = (LinearLayout) convertView;
    } else {
        lo = (LinearLayout) mLayoutInflater.inflate(R.layout.list_item_group_header, parent, false);
    }

    int visibility = mData.size() == 0 ? View.GONE : View.VISIBLE;
    for (int i = 0; i < lo.getChildCount(); i++) {
        lo.getChildAt(i).setVisibility(visibility);
    }
    return lo;
}
like image 3
Arst Avatar answered Nov 14 '22 03:11

Arst


Set the parent iew vlayout params hieght to zero in your BaseExpandableListAdapter so that you can hide you parent

like image 1
manojvemuru Avatar answered Nov 14 '22 05:11

manojvemuru