Reputation: 369
I use a ExpandableListView
in my Android application an want to perfrom an action if the user clicks long on the group element, so I defined a OnLongClickListener
in my BaseExpandableListAdapter
extention. The listener works as aspected but the child elements does not expand anymore. Any ideas?
public class ConnectionAdapter extends BaseExpandableListAdapter {
...
public View getGroupView(int groupPosition, boolean isExpanded, View convertView,
ViewGroup parent) {
// convertView is a LinearLayout
convertView.setOnLongClickListener(new OnLongClickListener() {
public boolean onLongClick(View v) {
// my action here
return true;
}
});
}
...
}
Upvotes: 5
Views: 5536
Reputation: 116
You can set setOnItemLongClickListener on your expandablelistview. ExpandableListView.PACKED_POSITION_TYPE_GROUP is the id of a group, change it to ExpandableListView.PACKED_POSITION_TYPE_CHILD and you can manipulate with longclicks on group childs.
Something like that:
pager_income = (ExpandableListView) findViewById(R.id.income_scroll);
pager_income.setOnItemLongClickListener(new OnItemLongClickListener() {
@Override
public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
if (ExpandableListView.getPackedPositionType(id) == ExpandableListView.PACKED_POSITION_TYPE_GROUP) {
// Your code with group long click
return true;
}
return false;
}
});
Upvotes: 4
Reputation: 34
The reason that your code is not further processing any other 'onClick' events is because you are passing a 'true' in your return. If you indicate that an event was handled, the OS stops attempting to further process any further events. To have it process THIS event, and also expand, then you need to change the return to false instead of true
Upvotes: 1