I'm following this: Programmatically collapse a group in ExpandableListView. I want the user capable to expand only one group at a time and smoothly scroll to the right position. I've written a custom adapter that implements OnGroupClickListener:
public class CategoriesListAdapter extends BaseExpandableListAdapter implements OnGroupClickListener {
private ExpandableListView expListView;
private int lastExpandedGroupPosition = -1;
// I get the expListView in the constructor...
@Override
public boolean onGroupClick(ExpandableListView parent, View view, int groupPosition, long id) {
parent.smoothScrollToPosition(groupPosition);
if (parent.isGroupExpanded(groupPosition)) {
parent.collapseGroup(groupPosition);
} else {
parent.expandGroup(groupPosition);
}
return true;
}
@Override
public void onGroupExpanded(int groupPosition) {
if (groupPosition != lastExpandedGroupPosition) {
expListView.collapseGroup(lastExpandedGroupPosition);
}
super.onGroupExpanded(groupPosition);
lastExpandedGroupPosition = groupPosition;
}
}
Unfortunately the onGroupClick event is never fired...(I've put some logs inside the method). I've also tried:
expListView.setOnGroupClickListener(new OnGroupClickListener() {
@Override
public boolean onGroupClick(ExpandableListView parent, View view, int groupPosition, long id) {
// Same as above...
});
}
Same results for this alternative...any ideas?