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");
}
しかし、コンテキストメニューはまったく開いていません。
理解するのを手伝ってください