Unable to override onCreateOptionsMenu in ListFragment

后端 未结 10 1741
太阳男子
太阳男子 2020-12-24 06:56

I created an app that supports both phone and tablet version so i use the android-support-v4.jar library.

My activity extends the ListFragment and I tried to overri

10条回答
  •  忘掉有多难
    2020-12-24 06:59

    Had the same problem, but it was because I used the wrong onCreateOptionsMenu method in my Fragment!

    boolean onCreateOptionsMenu(Menu menu) is only for Activities.

    @Override //For Activities
    public boolean onCreateOptionsMenu(Menu menu) { 
    ...
    

    Had to move it to the activity class containing the Fragment.

    Fragment have their own: void onCreateOptionsMenu (Menu menu, MenuInflater inflater)

    @Override //For Fragments.
    public void onCreateOptionsMenu (Menu menu, MenuInflater inflater){
    ...
    

    Creating an Options Menu: http://developer.android.com/guide/topics/ui/menus.html

提交回复
热议问题