充气上下文菜单中SherlockListFragment上下文、菜单中、SherlockListFragment

2023-09-06 10:34:09 作者:花落人憔悴

如何从XML在 SherlockListFragment 创建一个文本菜单。我知道(见例子)

How to create a Contextmenu from xml in a SherlockListFragment. i know (see in the examples)

@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) {
    menu.add("One");
    menu.add("Two");
    menu.add("Three");
    menu.add("Four");
}

这工作太为 SherlockListFragment ,但我想从菜单/ context_menu.xml膨胀

this work too for SherlockListFragment but i wanna inflate from a menu/context_menu.xml

推荐答案

过了一会儿,我找到了解决办法。

after a while i found the solution

@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
    getSherlockActivity().getMenuInflater().inflate(R.menu.context_menu, menu);
}