在ExpandableListView中创建ContextMenu

时间:2018-06-11 20:06:21

标签: android contextmenu expandablelistview

如何创建一个使用ExpandableListView头文件的ContextMenu?我必须得到所选项的标题,但是当我尝试使用AdapterContextMenuInfo时,编译器说,ExpandableListContextMenuInfo不能转换为AdapterContextMenuInfo。有没有办法让它发挥作用?

public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo){
    super.onCreateContextMenu(menu, v, menuInfo);

    AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuInfo;

    Adapter adapter = expListView.getAdapter();
    Object item = listAdapter.getGroupId(info.position);
    menu.setHeaderTitle(listOfItems.get((int) adapter.getItemId(info.position)).getTitle());

    menu.add(0, v.getId(), 0, "Add");
    menu.add(0, v.getId(), 0, "Delete");
}

0 个答案:

没有答案