Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I make some of the Items in ExpandableListView Not Expandable

I am writing a navigation system using the ExpandableListView widget, and I am able to have expandable lists, that function properly, but what about items in the navigation that have no submenus like Home and just transition straight to the Home Fragment? All of the Group Items appear as dropdown-able even though they don't have any children. Can I take away the dropdown icon from the parents that don't have children? Or can I only either, have Icons or not have icons.

like image 578
TheJavaCoder16 Avatar asked Nov 27 '25 09:11

TheJavaCoder16


1 Answers

To disable the expanding of the group items, you could set a GroupClickListener and return true if you want to disable the expansion.

ExpandableList.setOnGroupClickListener(new OnGroupClickListener() {
  @Override
  public boolean onGroupClick(ExpandableListView parent, View v,
                              int groupPosition, long id) { 
     return groupPosition == 0; //Index of item in your list that you want to be expandable
  }
});

As for the icons, you could define your own layout for the group items.

like image 182
dgzz Avatar answered Nov 29 '25 23:11

dgzz



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!