menu inflating calls multiple times at fragment's onCreateOptionsMenu

倾然丶 夕夏残阳落幕 提交于 2019-12-03 10:36:51

I solved it simply by clearing menu before ionflating of it:

     @Override
     public void   onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
          menu.clear();
          inflater.inflate(R.menu.call_menu, menu);
          super.onCreateOptionsMenu(menu, inflater);

     }

Just check the count of menu items. Meaning menu.size()==0 ,no menu items are present,then inflate with layout menu,else don't inflate at all.

 @Override
 public void   onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
      if (menu.size() == 0)
      inflater.inflate(R.menu.call_menu, menu);
      super.onCreateOptionsMenu(menu, inflater);

 }
shubomb

Use before replace.

 fragment = new EditMyProfile();
 FragmentTransaction fragmentTransactionEditProfile =getSupportFragmentManager().beginTransaction();
 getSupportFragmentManager().popBackStack(null, FragmentManager.POP_BACK_STACK_INCLUSIVE);
 fragmentTransactionEditProfile.replace(R.id.frame, fragment);
 fragmentTransactionEditProfile.commit();
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!