xxxxxxxxxx
navigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
@Override
public boolean onNavigationItemSelected(@NonNull MenuItem menuItem) {
int id=menuItem.getItemId();
//it's possible to do more actions on several items, if there is a large amount of items I prefer switch(){case} instead of if()
if (id==R.id.nav_home){
Toast.makeText(getApplicationContext(), "Home", Toast.LENGTH_SHORT).show();
}
//This is for maintaining the behavior of the Navigation view
NavigationUI.onNavDestinationSelected(menuItem,navController);
//This is for closing the drawer after acting on it
drawer.closeDrawer(GravityCompat.START);
return true;
}
});