Open a new activity after clicking a navigation menu item

Hi everyone, I am starting and starting coding in Android. I found a tutorial on how to make a navigation box.

Tutorial link: - http://www.android4devs.com/2015/06/navigation-view-material-design-support.html

I really want to know if there is any way, if I click on the options in the navigation box, a new action will open, it will be a big help for the answer.

Thank you in advance

+2
android android-activity navigation onclick
source share
5 answers
mDrawerList.setOnItemClickListener(new OnItemClickListener() { public void onItemClick(AdapterView<?> parent, View v, int position, long id) { switch (position) { case 1: Intent intent= new Intent(CurrentActivity.this,AnotherActivity.class); startActivity(intent); break; case 2: ... default: break; } } }); 
+2
source share

Im using

 public boolean onNavigationItemSelected(MenuItem item) { // Handle navigation view item clicks here. int id = item.getItemId(); if (id == R.id.nav_cinema) { Intent cinemaIntent = new Intent(this, CinemaActivity.class); startActivity(cinemaIntent); } else if (id == R.id.nav_tv) { } else if (id == R.id.nav_tvseason) { } else if (id == R.id.nav_share) { } else if (id == R.id.nav_send) { } DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout); drawer.closeDrawer(GravityCompat.START); return true; } 

and it works for me :) (This is the default menu for Android navigator)

+2
source share
  public boolean onNavigationItemSelected(MenuItem item) { // Handle navigation view item clicks here. int id = item.getItemId(); if (id == R.id.activity_about) { Intent activity_about = new Intent(this, AboutActivity.class); startActivity(activity_about); } else if (id == R.id.nav_gallery) { } else if (id == R.id.nav_slideshow) { } else if (id == R.id.nav_manage) { } else if (id == R.id.nav_share) { } else if (id == R.id.nav_send) { } DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout); drawer.closeDrawer(GravityCompat.START); return true; } 

}

+1
source share

as a new implementation, you can use the new design support library that introduced the NavigationView and DrawerLayout . See the release notes for more information.

0
source share
 if (id == R.id.activity_about) { Intent activity_about = new Intent(this, AboutActivity.class); startActivity(activity_about); 
0
source share

All Articles