Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to disable the collapsing of an ExpandableListView?

I would like to implement a ExpandableListView which should be expandable only after all the values have been set up within the adapter. Also I would like to be able to disable the collapsing of the expander.

Can I achieve this within an Android XML Layout?

like image 840
Jabeer Avatar asked Apr 30 '11 22:04

Jabeer


2 Answers

You can define a OnGroupClickListener which returns true, like so:

expandableList.setOnGroupClickListener(new OnGroupClickListener() {
  @Override
  public boolean onGroupClick(ExpandableListView parent, View v,
                              int groupPosition, long id) { 
    return true; // This way the expander cannot be collapsed
  }
});
like image 104
추몽이 Avatar answered Oct 18 '22 21:10

추몽이


There is no way that I know of this to be done from xml.

You could add an OnGroupClickListener to the ExpandableListView, and consume its event if the group is already expanded:

myExpandableListView.setOnGroupClickListener(new OnGroupClickListener()
{
    @Override
    public boolean onGroupClick(ExpandableListView parent, 
        View v, int groupPosition, long id)
    {
        return parent.isGroupExpanded(groupPosition);
    }
});
like image 33
rekaszeru Avatar answered Oct 18 '22 19:10

rekaszeru