Open new Activity after click item in navigation drawer menu

12,575

Solution 1

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;
    }
  }
});

Solution 2

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's work for me :) (It's the default android nav drawer menu)

Share:
12,575
Admin
Author by

Admin

Updated on June 04, 2022

Comments

  • Admin
    Admin almost 2 years

    Hello Everyone I am a beginner and just started coding in android i found a tutorial regarding, how to make navigation drawer.

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

    I do wanna know is there any way if i click on options in navigation drawer, a new activity will open it will be a great help for answer.

    Thank you in advance