Search code examples
androidexpandablelistview

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?


Solution

  • 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
      }
    });