Android Programming Tutorials

(Romina) #1

TUTORIAL 4


Adding a List


In this tutorial, we will change our model to be a list of restaurants, rather


than just one. Then, we will add a ListView to view the available restaurants.


This will be rather incomplete, in that we can only add a new restaurant,


not edit or delete an existing one, but we will cover those steps too in a later


tutorial.


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


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


beginning 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 03-FancierForm edition of LunchList to use as a starting point.


Step #1: Hold a List of Restaurants.....................................................


First, if we are going to have a list of restaurants in the UI, we need a list of


restaurants as our model. So, in LunchList, change:


Restaurant r=new Restaurant();

to:


List<Restaurant> model=new ArrayList<Restaurant>();

29
Free download pdf