I want to make an expandable listview
that should respond when the user clicks on one of the items/children of the listview
(onChildClickListener?). Can anyone help with the code? I have already made an expandable listview
in which I have made my own adapter and dataprovider classes, but I do not know how to code the onItemClick
part.
Asked
Active
Viewed 2,127 times
0

Vadim Kotov
- 8,084
- 8
- 48
- 62

VanDijk1234
- 1
- 3
1 Answers
7
You need to set separate click listeners for child and group item as follows
expandableListView.setOnChildClickListener(new ExpandableListView.OnChildClickListener() {
@Override
public boolean onChildClick(ExpandableListView expandableListView, View view,
int groupPosition, int childPosition, long l) {
Item item = (Item) topicListAdapter.getChild(groupPosition,childPosition);
handleClick(item);
return false;
}
});
expandableListView.setOnGroupClickListener(new ExpandableListView.OnGroupClickListener() {
@Override
public boolean onGroupClick(ExpandableListView expandableListView, View view, int groupPosition, long l) {
Item item = (item) topicListAdapter.getGroup(groupPosition);
handleClick(item);
return false;
}
});

rabhis
- 440
- 2
- 5