Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable collapsing of ExpandableListView

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.

like image 646
Justin Avatar asked Aug 11 '10 19:08

Justin


Video Answer


2 Answers

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;
  }
});
like image 68
Andrus Avatar answered Oct 19 '22 01:10

Andrus


Maybe It`s too late,I use onGroupCollapseListener in the activity and implement onGroupCollapse Method.(expandView is ExpandableListView)

@Override
public void onGroupCollapse(int collapseIndex) {
    expandView.expandGroup(collapseIndex);
}
like image 42
Wangchao0721 Avatar answered Oct 18 '22 23:10

Wangchao0721