LittleGuy
LittleGuy

Reputation: 11

Item navigation drawer open activity

I created a Navigation Drawer and inserted the necessary items and their fragments. Also, I added a item that I have to open another Activity, which code should I put that by pressing on the item do this? For example, item id nav_menu6 ..... but it should not be linked to a fragment but open an activity ...

private void displaySelectedScreen(int itemId) {

        Fragment fragment = null;
        // Handle navigation view item clicks here.
        switch (itemId) {
            case R.id.nav_menu1:
                fragment = new BlankFragment();
                break;
            case R.id.nav_menu2:
                fragment = new BlankFragment2();
                break;
            case R.id.nav_menu3:
                fragment = new BlankFragment3();
                break;
            case R.id.nav_menu4:
                fragment = new BlankFragment4();
                break;
            case R.id.nav_menu5:
                fragment = new BlankFragment5();
                break;
            case R.id.nav_menu6:
                fragment = new BlankFragment6();
                break;
        }

Upvotes: 0

Views: 45

Answers (1)

barotia
barotia

Reputation: 428

https://developer.android.com/training/basics/firstapp/starting-activity.html

Read this about starting a new activity. Basically, the key is the intent.

Intent intent = new Intent(this, YourActivityName.class);
startActivity(intent);

or in a shortened form:

startActivity(new Intent(this, YourActivityName.class));

Upvotes: 1

Related Questions