Skip to content
Advertisement

How to change fragments using Android navigation drawer

I know these types of question have already been here but still I have not found my answer for this question:

  • I have created an application and used navigation drawer that has been created AUTOMATICALLY by the app (AndroidStudio)

Here’s what I have:

JavaScript

And some more here:

JavaScript

I want to display another fragment using the button in navigation drawer. I want to use this code so please do not send me any guides or tutorials making their own drawers..

The question is, what do I put in case 1: case 2: and case 3: in case I want to open another fragment? Thanks.

One more question:

  • How do I add more fragments and transactions? This doesn’t work-

    JavaScript

Advertisement

Answer

You should just put a switch statement into the onNavigationDrawerItemSelected method.

Something like this should work:

JavaScript

This is just done quickly but I think it should work

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement