1

The idea is to temporarily hide an option menu for a specific fragment. If the user is signed in, the system should hide the menu.

In all other fragments the menu should be implemented and enabled.

public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()){
        case R.id.menu_main_home: 
            if (MainActivity.isSignedIn() == true){   
               (signedIn == false)
                forwardToWelcomeFragment();
            } else {
                Toast.makeText(this, "You are not logged in.",    
                Toast.LENGTH_SHORT).show();
                forwardToLoginFragment();
            }
            return true;
            case R.id.menu_main_settings:
            Toast.makeText(this, "", Toast.LENGTH_SHORT).show();
            return true;
            case R.id.menu_main_info:
            Toast.makeText(this, "", Toast.LENGTH_SHORT).show();
            return true;
            case R.id.menu_main_signout:
            Toast.makeText(this, "", Toast.LENGTH_SHORT).show();
            setSignedIn(false);
            forwardToLoginFragment();
            return true;
            default:
            return super.onOptionsItemSelected(item);
         }

0 Answers0