Using the Fragment classes and their layouts

This stage has three steps. First, we need to edit the menu of the Navigation Drawer to reflect the options the user has. Next, we need a View in the layout to hold whatever the active Fragment instance is, and finally, we need to add code to MainActivity.java to switch between the different Fragment instances when the user taps on the menu.

Editing the Navigation Drawer menu

Open the activity_main_drawer.xml file in the res/menu folder of the project explorer. Edit the code within the group tags that we saw earlier to reflect our menu options of Insert, Delete, Search, and Results:

<group android:checkableBehavior="single"> <item android:id="@+id/nav_insert" android:icon="@drawable/ic_menu_camera" android:title="Insert" ...

Get Android Programming for Beginners - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.