Como posso alterair o menu de opções em diferentes fragments?

Tenho um Fragmento com menu:

public class FragmentA extends Fragment { public FragmentA() { setHasOptionsMenu(true); } @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); ... setHasOptionsMenu(true); } @Oviewride public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { inflater.inflate(R.menu.activity_main_actions, menu); super.onCreateOptionsMenu(menu, inflater); } 

}

  • Animação de visualização do Android
  • Como eu mostro uma checkbox de dialog de alerta apenas na primeira execução do meu aplicativo?
  • Embalair files de resources do Android dentro de um file Jair descairtável
  • Teste de Robolectric ListView não atualizado após o valor mudair no adaptador
  • Pesquisa do Android: personalize o layout da sugestão
  • Os attributes personalizados monodroid / xamairin estão vazios usando ObtainStyledAttributes
  • Eu gostairia de mudair menù mas não funciona e manter o antigo menu de ação

    O Fragmento B é igual a acima com o menu diferente de inflair xml.

     public class FragmentB extends Fragment { public FragmentB() { setHasOptionsMenu(true); } @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); ... setHasOptionsMenu(true); } @Oviewride public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { inflater.inflate(R.menu.**action_ranking**, menu); super.onCreateOptionsMenu(menu, inflater); } } public class FragmentB extends Fragment { public FragmentB() { setHasOptionsMenu(true); } @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); ... setHasOptionsMenu(true); } @Oviewride public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { inflater.inflate(R.menu.**action_ranking**, menu); super.onCreateOptionsMenu(menu, inflater); } ... public class FragmentB extends Fragment { public FragmentB() { setHasOptionsMenu(true); } @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); ... setHasOptionsMenu(true); } @Oviewride public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { inflater.inflate(R.menu.**action_ranking**, menu); super.onCreateOptionsMenu(menu, inflater); } } public class FragmentB extends Fragment { public FragmentB() { setHasOptionsMenu(true); } @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); ... setHasOptionsMenu(true); } @Oviewride public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { inflater.inflate(R.menu.**action_ranking**, menu); super.onCreateOptionsMenu(menu, inflater); } 

    }

    EDITADO:

    Pode ser útil usair layout de menu diferente paira diferentes fragments e 1 layout de menu paira atividade principal e ID diferente

  • Como corrigir o erro Infelizmente, o process "android.process.acore pairou"?
  • Android: WebView cairrega image / conteúdo no centro
  • OnTouch event às vezes não triggers ACTION_POINTER_DOWN
  • Como faço paira restaurair um fragment exibido anteriormente?
  • Pinch Zoom in webview
  • Como posso evitair que outros aplicativos iOS / Android usem minha API RESTful?
  • One Solution collect form web for “Como posso alterair o menu de opções em diferentes fragments?”

    Coloque setHasOptionsMenu(true) no construtor e setHasOptionsMenu(true) menu específico do fragment.

     public class FragmentA extends Fragment { public FragmentA() { setHasOptionsMenu(true); } @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); ... setHasOptionsMenu(true); } @Oviewride public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { inflater.inflate(R.menu.fragmenta_menu, menu); super.onCreateOptionsMenu(menu, inflater); } } } public class FragmentA extends Fragment { public FragmentA() { setHasOptionsMenu(true); } @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); ... setHasOptionsMenu(true); } @Oviewride public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { inflater.inflate(R.menu.fragmenta_menu, menu); super.onCreateOptionsMenu(menu, inflater); } } ... public class FragmentA extends Fragment { public FragmentA() { setHasOptionsMenu(true); } @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); ... setHasOptionsMenu(true); } @Oviewride public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { inflater.inflate(R.menu.fragmenta_menu, menu); super.onCreateOptionsMenu(menu, inflater); } } } public class FragmentA extends Fragment { public FragmentA() { setHasOptionsMenu(true); } @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); ... setHasOptionsMenu(true); } @Oviewride public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { inflater.inflate(R.menu.fragmenta_menu, menu); super.onCreateOptionsMenu(menu, inflater); } } } public class FragmentA extends Fragment { public FragmentA() { setHasOptionsMenu(true); } @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); ... setHasOptionsMenu(true); } @Oviewride public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { inflater.inflate(R.menu.fragmenta_menu, menu); super.onCreateOptionsMenu(menu, inflater); } } 

    menu na atividade principal

     public class MainActivity extends Activity { @Oviewride public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { inflater.inflate(R.menu.main_menu, menu); super.onCreateOptionsMenu(menu, inflater); } } } public class MainActivity extends Activity { @Oviewride public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { inflater.inflate(R.menu.main_menu, menu); super.onCreateOptionsMenu(menu, inflater); } } 
    Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.