我有一个 ListFragment,我必须添加一个菜单。这是我的代码:listuser_menu:
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="@+id/any_option"
android:title="In Context Menu" />
</menu>
我的列表片段:
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
View mFooterView;
// We need to use a different list item layout for devices older than Honeycomb
int layout = Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB ?
android.R.layout.simple_list_item_activated_1:android.R.layout.simple_list_item_1;
if(getListAdapter()==null){
// init adapter
adapter=new UserArrayAdapter(getActivity(),
MOBILE_OS);
}
else{
adapter.notifyDataSetChanged();
}
// set adapter
registerForContextMenu(getListView());
setListAdapter(adapter);
}
@Override
public void onCreateContextMenu(final ContextMenu menu, final View v,
final ContextMenuInfo menuInfo){
menu.clear();
super.onCreateContextMenu(menu, v, menuInfo);
final MenuInflater inflater = getActivity().getMenuInflater();
inflater.inflate(R.menu.listuser_menu, menu);
}
但是我看不到我的菜单..为什么?如何注册选项菜单选择?谢谢!