Skip to content
Advertisement

Starting a new activity on navigation drawer item click

I know this is a question frequently asked, but after reading the many questions and solutions on stack overflow I am confused. I am confused with regards to Fragments and what is required to start an activity from clicking an item in the navigation drawer.

I’ve checked these posts but only got confused Q1, Q2

Could someone please explain what is required to start a basic activity from this navigation drawer item? Do I need an onClick method implemented where specified in the code? Also how does this relate to the Intent?

Here is my MainActivity.java

JavaScript

And here is the second activity, Playboard.java, that simply loads a background image:

JavaScript

All input greatly appreciated thanks!

Advertisement

Answer

For each case statement you just need to specify which Activity you want to start via an Intent.

Say for example you want to start the Playboard activity when navigation_item_1 is selected.

You would add this code to that particular case.

JavaScript
Advertisement