Question

I want have a menu for each group in my ExpandableList when long clicking on it. But at the moment only the non-empty groups show a blue background when longclicking and are selectable. All empty groups don't react to a long click.

I register the list to the fragment with registerForContextMenu(list) and wrote following code:

@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
    MenuInflater inflater = getActivity().getMenuInflater();
    inflater.inflate(R.menu.item_task_long_click_menu, menu);
}

@Override
public boolean onContextItemSelected( android.view.MenuItem item) {
    ExpandableListContextMenuInfo info = (ExpandableListView.ExpandableListContextMenuInfo) item.getMenuInfo();

    switch(item.getItemId()) {
        case R.id.itlcm_menu_edit:
            //do something
            break;  
        case R.id.itlcm_menu_remove:
            //do something
            break;
    }
    return true;
}

In the adapter I set:

@Override
public boolean isChildSelectable(int groupPosition, int childPosition) {
    return false;
}

Why are the empty groups not selectable? Haven't found a method to change that...

EDIT: I guess it's the

registerForContextMenu(list)

maybe the groups without any children are not registered to the long click....

Anybody?

Was it helpful?

Solution

I was able to solve it.

The problem wasn't at the registerForContextMenu(). The issue was my custom ExpandableListAdapter where I used two diffrent views for the GroupViews (getGroup(...)). The one that didn't react to any clicking at all contained a CheckBox which override the focus of the whole GroupView. So I added:

android:focusable="false" 

to the CheckBox in the XML and voila, the GroupView with the CheckBox reacted to the clicks.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top