我想为 android 中的可扩展列表子项实现上下文菜单。我正在使用以下代码 -
mExpandableListView.setOnItemLongClickListener(new OnItemLongClickListener() {
@Override
public boolean onItemLongClick(AdapterView<?> arg0, View view,
int arg2, long arg3) {
int type =ExpandableListView.getPackedPositionType(arg3);
int groupPos = ExpandableListView.getPackedPositionGroup(arg3);
int childPos = ExpandableListView.getPackedPositionChild(arg3);
if(type==ExpandableListView.PACKED_POSITION_TYPE_CHILD){
registerForContextMenu(getExpandableListView().getChildAt(arg2));
Toast.makeText(getApplicationContext(), "Hello Hello"+" "+groupPos+" "+childPos, 0).show();
}
return true;
}
});
@Override
public void onCreateContextMenu(ContextMenu menu, View v,
ContextMenuInfo menuInfo) {
// TODO Auto-generated method stub
super.onCreateContextMenu(menu, v, menuInfo);
ExpandableListView.ExpandableListContextMenuInfo info =
(ExpandableListView.ExpandableListContextMenuInfo) menuInfo;
int type =
ExpandableListView.getPackedPositionType(info.packedPosition);
int group =
ExpandableListView.getPackedPositionGroup(info.packedPosition);
int child =
ExpandableListView.getPackedPositionChild(info.packedPosition);
menu.setHeaderTitle("CCM");
menu.setHeaderIcon(R.drawable.ic_launcher);
menu.add(0, v.getId(), 0, "HelloCCM");
}
但是根本没有打开上下文菜单。
请帮我弄清楚