Reputation: 2881
I have a custom ExpandableListView elv and I am able to detect when a Child is clicked with the code below.
elv.setOnChildClickListener(new OnChildClickListener() {
public boolean onChildClick(ExpandableListView parent, View v, int groupPosition,
int childPosition, long id) {
However, when I change it to try to detect when a group item is clicked, this does not work. Does anyone know why?
Eclipse gives me the error:
The method setOnGroupClickListener(ExpandableListView.OnGroupClickListener) in the type ExpandableListView is not applicable for the arguments (new OnGroupClickListener(){})
elv.setOnGroupClickListener(new OnGroupClickListener() {
public boolean onGroupClick(ExpandableListView parent, View v, int groupPosition,
long id) {
Upvotes: 1
Views: 11153
Reputation: 1145
private ExpandableListView listView;
listView.setOnChildClickListener(new ExpandableListView.OnChildClickListener() {
@Override
public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id) {
//get header
TextView lbListenerHeader = parent.findViewById(R.id.lbListHeader);
String data1= lbListenerHeader.getText().toString();
Toast.makeText(getContext(),data1 ,Toast.LENGTH_SHORT).show();
//get list item
TextView tv= (TextView) v.findViewById(R.id.lbListItem);
ExpandableListView elv= (ExpandableListView) parent.findViewById(R.id.lvExp);
String data= tv.getText().toString();
Toast.makeText(getContext(),data ,Toast.LENGTH_SHORT).show();
return true;
}
});
Upvotes: 0
Reputation: 1385
These methods can also be used inside ExpandableListAdapter
public void onGroupExpanded(int groupPosition) {}
public void onGroupCollapsed(int groupPosition) {}
Upvotes: 0
Reputation: 9258
Make sure you have imported android.widget.ExpandableListView.OnGroupClickListener
right or replace
new OnGroupClickListener() {
with new android.widget.ExpandableListView.OnGroupClickListener {
Upvotes: 7