Android ExpandableListView中的ContextMenu

Android ExpandableListView中的ContextMenu,android,contextmenu,expandablelistview,childviews,Android,Contextmenu,Expandablelistview,Childviews,在我的应用程序中,我使用expandableListView。我需要为可扩展的listView集成一个contextMenu。在我的可展开列表视图中,我为不同的子对象展开不同的布局。因此,当我长时间单击每个childView时,我需要执行不同的操作 这里我给出了ContextMenu的代码 @Override public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {

在我的应用程序中,我使用expandableListView。我需要为可扩展的listView集成一个contextMenu。在我的可展开列表视图中,我为不同的子对象展开不同的布局。因此,当我长时间单击每个childView时,我需要执行不同的操作

这里我给出了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);
}
registerForContextMenu(expListView);
在onCreate()中,我注册了listView 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);
}
registerForContextMenu(expListView);

但当我按下GroupView时,它会显示contextMenu。但是当我点击childView时,它不会显示ContextMenu。。请帮帮我……

用这个它对我有用。 将适配器设置为可扩展ListView后,编写它

setListAdapter(expListAdapter);
            registerForContextMenu(getExpandableListView());

用这个它对我有用。 将适配器设置为可扩展ListView后,编写它

setListAdapter(expListAdapter);
            registerForContextMenu(getExpandableListView());
只需使用:

@Override
public boolean isChildSelectable(int groupPosition, int childPosition) {
    return true;
}
在ExpandableListViewAdapter中,只需使用:

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

在ExpandableListViewAdapter中,您还必须在适配器的
getChildView(…)
中将视图设置为可长点击

public View getChildView(int groupPosition, final int childPosition, boolean isLastChild, View convertView, ViewGroup parent) {
    ... 
    convertView.setLongClickable( true);

您还必须在适配器的
getChildView(…)
中将视图设置为可长点击

public View getChildView(int groupPosition, final int childPosition, boolean isLastChild, View convertView, ViewGroup parent) {
    ... 
    convertView.setLongClickable( true);