【发布时间】:2011-11-30 16:42:32
【问题描述】:
我有这个代码:
@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);
int group =
ExpandableListView.getPackedPositionGroup(info.packedPosition);
int child =
ExpandableListView.getPackedPositionChild(info.packedPosition);
//Only create a context menu for child items
if (type == 1) {
//menu.setHeaderTitle("Action");
menu.add(0, MENU_EDIT, 0, "Edit");
menu.add(0, MENU_DELETE, 1, "Delete");
}
}
@Override
public boolean onContextItemSelected(MenuItem item) {
ExpandableListContextMenuInfo info = (ExpandableListContextMenuInfo) item.getMenuInfo();
AdapterContextMenuInfo info1 = (AdapterContextMenuInfo) item.getMenuInfo();
int groupPos = 0, childPos = 0;
int type = ExpandableListView.getPackedPositionType(info.packedPosition);
if (type == ExpandableListView.PACKED_POSITION_TYPE_CHILD) {
groupPos = ExpandableListView.getPackedPositionGroup(info.packedPosition);
childPos = ExpandableListView.getPackedPositionChild(info.packedPosition);
}
return true;
switch (item.getItemId()) {
case MENU_DELETE:
return true;
}
return(super.onOptionsItemSelected(item));
}
我想删除项目,如何填写case MENU_DELETE: 的代码?这是可扩展列表视图和上下文菜单的组合,我想通过上下文菜单删除子项。感谢您的帮助和解释
【问题讨论】:
标签: android contextmenu hashmap expandablelistview