In ExpandableListView if I only have one group. I want to hide that group, only the group's data show that. Please help me
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!
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
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;
}
Set the parent iew vlayout params hieght to zero in your BaseExpandableListAdapter so that you can hide you parent
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With