Search code examples
androidactionbarsherlockandroid-listfragment

Inflate context menu in a 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");
}

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


Solution

  • 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);
    }