Android Programming Tutorials

(Romina) #1

TUTORIAL 33


A Restaurant In Your Own


Home


In this tutorial, we will create an "app widget", the term Android uses for


interactive elements a user can add to their home screen. In particular, we


will create an app widget that shows a random restaurant out of the


LunchList database.


Step-By-Step Instructions........................................................................


First, you need to have completed the previous LunchList tutorial. If you are


starting the tutorials here, or if you wish to not use your existing work, you


can download a ZIP file with all of the tutorial results, and you can copy the


31-Search edition of LunchList to use as a starting point.


Step #1: Find An App Widget Background and Icon


We are going to need a background to use for our app widget, so its


contents do not seem to float in empty space in the home screen. Ideally,


this background is resizeable, so we have a choice of using an XML-defined


drawable resource, or a nine-patch PNG.


If you examine the 33-AppWidget project in the book's source code


repository, you will see that there is a widget_frame.9.png file in


LunchList/res/drawable. That nine-patch image works nicely for your app


315
Free download pdf