Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.

  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint

A Main Menu

Main menus can take any number of forms. From games to music apps, they provide a top-level navigation into the app as a whole.

They are also, as a happy side effect, a great way to introduce you to how lists work. I’ll be creating an array of strings for the resource manager, feeding it to an array adapter, and plugging that array adapter into the list view contained by a list activity. Got all that? There are a lot of moving parts to collect when dealing with lists, so I’ll take it slowly and step by step.

Creating the Menu Data

A menu must have something to display, so you need to create a list of strings to be displayed. Remember the chapter where you learned that all displayed string constants should go into the res/values/strings.xml file? String arrays, coincidentally, go into the same file, but with a slightly different syntax. I’ve added the following to my res/values/strings.xml file:


  

You are currently reading a PREVIEW of this book.

                                                                                                                    

Get instant access to over $1 million worth of books and videos.

  

Start a Free 10-Day Trial


  
  • Safari Books Online
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint