Disable collapsing of ExpandableListView
Asked Answered
R

4

19

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.

Retreat answered 11/8, 2010 at 19:53 Comment(2)
This worked for me -> stackoverflow.com/questions/3464599.Astringent
While helpful, that thread does not answer my stated question.Retreat
R
2

It seems the problem had to do with there being both a focusable element in the group header and an OnGroupClickListener set. Removing the listener solved my problem.

Retreat answered 11/8, 2010 at 21:2 Comment(2)
didn't solve it for me (I hadn't even set one in the first place). I have clickable elements inside the header, but the header itself should not be clickable.Sib
OnGroupClickListener(null);Kilter
S
32

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;
  }
});
Skiplane answered 12/11, 2012 at 16:3 Comment(0)
C
15

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);
}
Cowgirl answered 11/9, 2011 at 7:1 Comment(1)
I think this should not be implemented! Andrus way is better!Efrainefram
B
3

You can use this code on the item for which you want to disable clicking on: {convertView.setClickable(false);}

Brassy answered 19/2, 2016 at 3:50 Comment(1)
perfect code if you want to disable click on the particular conditionOtway
R
2

It seems the problem had to do with there being both a focusable element in the group header and an OnGroupClickListener set. Removing the listener solved my problem.

Retreat answered 11/8, 2010 at 21:2 Comment(2)
didn't solve it for me (I hadn't even set one in the first place). I have clickable elements inside the header, but the header itself should not be clickable.Sib
OnGroupClickListener(null);Kilter

© 2022 - 2024 — McMap. All rights reserved.