Starting a new activity on navigation drawer item click
Instead of
NavigationUI.setupWithNavController(navigationView, navController);
Do this
navigationView.setNavigationItemSelectedListener(new
NavigationView.OnNavigationItemSelectedListener() {
@Override
public boolean onNavigationItemSelected(@NonNull MenuItem item) {
Toast.makeText(MainActivity.this, "clicked", Toast.LENGTH_SHORT).show();
return false;
}
}
);
For each case statement you just need to specify which Activity
you want to start via an Intent
.
Say for example you want to start the Playboard
activity when navigation_item_1
is selected.
You would add this code to that particular case
.
case R.id.navigation_item_1:
Intent i = new Intent(MainActivity.this, Playboard.class);
startActivity(i);
break;