1

I got my navigation menu and I can't activate a function when an item is being clicked on. I don't get any id on my log console. I have tied using switch and it didn't work. My menu can open perfectly. I hope someone will know how to fix it.

public class SummeyAct extends AppCompatActivity {
    Context context;
    FirebaseAuth firebaseAuth;
    private DrawerLayout drawerLayout;
    private ActionBarDrawerToggle actionBarDrawerToggle;
    Intent intent;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_summey);
        drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
        actionBarDrawerToggle = new ActionBarDrawerToggle(this ,drawerLayout, R.string.open, R.string.close);
        drawerLayout.addDrawerListener(actionBarDrawerToggle);
        actionBarDrawerToggle.syncState();

        getSupportActionBar().setDisplayHomeAsUpEnabled(true);


        context = this;
    }
@Override
    public boolean onOptionsItemSelected(MenuItem item) {


        Log.d("menu id",String.valueOf(item.getItemId()));

        switch (item.getItemId()) {
            case R.id.PlayerListMenu:
                Intent intent = new Intent(context, Players.class);
                startActivity(intent);
                return true;
            case R.id.FanChatMenu:
                Intent intent2 = new Intent(context, Players.class);
                startActivity(intent2);
                return true;
            case R.id.SighnOutMenu:
                LogOutMethod();
                return true;


        }
        if(actionBarDrawerToggle.onOptionsItemSelected(item))
        {
            return true;
        }

        return super.onOptionsItemSelected(item);
    }
Cœur
  • 37,241
  • 25
  • 195
  • 267
Uri Aviv
  • 15
  • 1
  • 4

1 Answers1

0

You need to add setNavigationItemSelectedListener on your navigation view and get the callbacks on click on there. Check out answer on this StackOverflow question

karandeep singh
  • 2,294
  • 1
  • 15
  • 22