1 – Introduction
The Android ListView object is meant to build scrollable items lists; is one of the most used user interfaces in the mobile applications. An Android ListView corresponds to an iPhone TableView.
Bare in mind that the code examples I will use in this post refear to the Android SDK 1.5; at the time I am writing the latest SDK version is the 2.2 and some methods/classes could be now deprecated. Moreover, all the import statements are omitted for semplicity.
This post will try to clarify how to setup a ListView in your Android v1.5 application; I spent time to understand it and now I personally feel that it could be improved cause the steps you need to take in order to build a ListView, even if few, need to be repeated for all the ListView objects you have in your application.
In the following paragraphs we will see how to setup these objects and later we will see a solution I’ve found during the development of Scanean to reduce this steps and use the same ListView object to implement different ListViews.
2 – Create a ListView
A ListView is a set of scrollable items; these items are a set of graphic objects (Images, TextViews…) disposed in a particular way that is described by an xml file stored in the
According with the explanation above, in order to setup a ListView we have to perform te following steps:
- Create an xml layout template for the single ListView item (e.g. tpl_menu_item.xml)
- Create an xml layout template for the page that will host our ListView component (e.g. menu.xml)
- Create a bean that describes the single item (e.g. MenuItem.java); basically it’s a set of setter/getter methods used to assign a proper values to the item subcomponent (e.g. TextView content is “Products” and the related image is “Product.gif”)
- Create a wrapper java class that populate the single item template with the right values (e.g. MenuItemWrapper.java).
- Create an adapter JAVA class that will populate the ListView template (e.g. MenuItemAdapter.java)
- Create the activity class associated to the ListView (e.g. A_MENU.java)
Total number of object to create in order to setup a single ListView: 6



