January 2013
Intermediate to advanced
408 pages
9h 23m
English
If you have a long list of items that you want to display to the user, the ListView view is the answer. This recipe demonstrates how to use the ListView to display a list of items contained within an array.
To use the ListView, use the <ListView> element and put it into your UI file, such as the activity_main.xml file:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<ListView
android:id="@+id/android:list"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</RelativeLayout>
In the activity, extend the ListActivity base class and use the setListAdapter() method to bind the ListView to an ArrayAdapter object (which in turn loads the string array). You specify the type of ListView you want by specifying the android.R.layout.simple_list_item_1 constant, which ...
Read now
Unlock full access