1

hi frnds in my application i use expandableListView. an i need to integrate a contextMenu for the expandable listView. in my expandable ListView i inflate different layouts for different child. so when i do a long click on each childView i need to perform different action.

here i gives the code for ContextMenu.

@Override
public void onCreateContextMenu(ContextMenu menu, View v,
        ContextMenuInfo menuInfo) {
    super.onCreateContextMenu(menu, v, menuInfo);
    ExpandableListView.ExpandableListContextMenuInfo info=
            (ExpandableListView.ExpandableListContextMenuInfo)menuInfo;
    int type=ExpandableListView.getPackedPositionType(info.packedPosition);
    Log.e("type",""+type);
    menu.setHeaderTitle("Options");
    menu.add(1, 1, 1, "Edit");
}
@Override
public boolean onContextItemSelected(MenuItem item) {
    ExpandableListView.ExpandableListContextMenuInfo info = (ExpandableListView.ExpandableListContextMenuInfo)item.getMenuInfo();

    if(item.getItemId()==1)
    {
        Log.e("clickd","menu");
    }
    return super.onContextItemSelected(item);
}

and in my onCreate() i register the listView forContextMenu.

registerForContextMenu(expListView);

but when i press on the GroupView it desplay the contextMenu. but when i click on the childView it doesn't shows the ContextMenu.. pls help me.....

Vikky
  • 933
  • 2
  • 15
  • 29

3 Answers3

3

Use this one it worked for me. After setting your adapter to Expandable ListView write it.

setListAdapter(expListAdapter);
            registerForContextMenu(getExpandableListView());
Mahaveer Muttha
  • 1,727
  • 4
  • 21
  • 33
2

You have also to set the view to be long clickable in getChildView(...) of your Adapter.

public View getChildView(int groupPosition, final int childPosition, boolean isLastChild, View convertView, ViewGroup parent) {
    ... 
    convertView.setLongClickable( true);
Peter O.
  • 32,158
  • 14
  • 82
  • 96
Lunero
  • 666
  • 1
  • 8
  • 17
1

Just use:

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

in your ExpandableListViewAdapter