0
我有這樣的代碼:如何刪除通過Android上Expandable Listview上的上下文菜單選擇的項目?
@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));
}
我想刪除的項目,我怎麼能填補的情況下MENU_DELETE的代碼:這是可擴展列表視圖和上下文菜單的結合,我想通過上下文菜單刪除孩子。 THX的幫助和解釋
看一看這個鏈接http://steveoliverc.wordpress.com/category/android/ – mH16