Skip to content Skip to sidebar Skip to footer

How Can I Call One Of My Activity Using Navigation Drawer ?

I have my navigation drawer activity as my MainActivity class and I already have Homepage.class activity previously made. Since Navigation Drawer uses Fragments, I am unable to cal

Solution 1:

The API for starting an Activity does not change when using a navigation drawer. You still only need to call startActivity() to launch a different Activity.

In this case, your code will look something like this:

privatevoiddisplayView(int position) {
    // update the main content by replacing fragments
    Fragment fragment = null;
    switch (position) {
        case0: // Or whatever nav item position should start the Activity
            startActivity(new Intent(this, HomePage.class));
            return;

        // The rest of your cases
}

Note that when after calling startActivity() for the homepage item, we return instead of break so that your displayView() doesn't try to replace the displayed Fragment.

Post a Comment for "How Can I Call One Of My Activity Using Navigation Drawer ?"