我想在启动片段时禁用菜单选项,但当我回到主屏幕时,我希望该选项可见。我试图在onresume中将可见性设置为true,但它会给出空指针异常
public boolean onNavigationItemSelected(MenuItem paramMenuItem)
{
FragmentManager localFragmentManager = getSupportFragmentManager();
WebViewFragment localWebViewFragment = new WebViewFragment();
ContactUsFragment contactus = new ContactUsFragment();
Bundle localBundle = new Bundle();
switch (paramMenuItem.getItemId())
{
case R.id.signin:localFragmentManager.beginTransaction().replace(R.id.frame_replace, new SignInFragment()).addToBackStack("signIn").commit();
break;
case R.id.drawer_book_your_car:
if ((PrefUtils.getDefaults("isSignedIn", this.mContext) == null) || (PrefUtils.getDefaults("isSignedIn", this.mContext).equalsIgnoreCase("false")) || (PrefUtils.getDefaults("isSignedIn", this.mContext).equalsIgnoreCase("")))
{
Toast.makeText(this.mContext, "Please Sign In", Toast.LENGTH_LONG).show();
return true;
}
break;
case R.id.drawer_myTrip:localFragmentManager.beginTransaction().replace(R.id.frame_replace, new TripFragment()).addToBackStack("MyTrip").commit();
break;
case R.id.drawer_tariff:startActivity(new Intent(this.mContext, TariffActivity.class));
break;
case R.id.how_to_broom:
localBundle.putString("url","www.abc.com");
localWebViewFragment.setArguments(localBundle);
localFragmentManager.beginTransaction().replace(R.id.frame_replace,localWebViewFragment).addToBackStack("web").commit();
localMenuItem.setVisible(false);
break;
case R.id.drawer_FAQs:
localBundle.putString("url","www.abc.com");
localWebViewFragment.setArguments(localBundle);
localFragmentManager.beginTransaction().replace(R.id.frame_replace, localWebViewFragment).addToBackStack("web").commit();
localMenuItem.setVisible(false);
break;
case R.id.drawer_policies:
localBundle.putString("url","www.abc.com");
localWebViewFragment.setArguments(localBundle);
localFragmentManager.beginTransaction().replace(R.id.frame_replace,localWebViewFragment).addToBackStack("web").commit();
localMenuItem.setVisible(false);
break;
case R.id.contactUs:
localBundle.putString("url", "www.abc.com");
localWebViewFragment.setArguments(localBundle);
localFragmentManager.beginTransaction().replace(R.id.frame_replace,contactus).addToBackStack("web").commit();
break;
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.DONUT) {
((DrawerLayout)findViewById(R.id.drawer_layout)).closeDrawer(GravityCompat.START);
}
return true;
}
public void onResume(){
super.onResume();
localMenuItem.setVisible(false);
}