Open new Activity after click item in navigation d

2019-07-10 03:55发布

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

5条回答
乱世女痞
2楼-- · 2019-07-10 03:56
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;
    }
  }
});
查看更多
兄弟一词,经得起流年.
3楼-- · 2019-07-10 04:01

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)

查看更多
Summer. ? 凉城
4楼-- · 2019-07-10 04:03
if (id == R.id.activity_about) {
    Intent activity_about = new Intent(this, AboutActivity.class);
    startActivity(activity_about);
查看更多
疯言疯语
5楼-- · 2019-07-10 04:15

as new implementation you can use the fresh Design Support Library that introduced the NavigationView class and DrawerLayout pattern. Check the release notes for more info.

查看更多
我命由我不由天
6楼-- · 2019-07-10 04:21
 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;
}

}

查看更多
登录 后发表回答