Disable collapsing of ExpandableListView

Justin picture Justin · Aug 11, 2010 · Viewed 18.1k times · Source

The default behavior of ExpandableListView is to collapse a group when its header is clicked. Is it possible to prevent this from happening?

I've tried:

  • Setting OnTouchListener on the list. This interferes with scrolling.
  • Setting an OnGroupClickListener on the list (in onCreate()). This works for all clicks after the first.

Has anyone else accomplished this? Why might the OnGroupClickListener miss the first click?

Thanks in advance for your suggestions.

Answer

Andrus picture Andrus · Nov 12, 2012

You can ignore click on group items like this:

mMyExpandableListView.setOnGroupClickListener(new ExpandableListView.OnGroupClickListener() {
  @Override
  public boolean onGroupClick(ExpandableListView parent, View v, int groupPosition, long id) {
      // Doing nothing
    return true;
  }
});