Presentation is loading. Please wait.

Presentation is loading. Please wait.

ANDROID LISTS.

Similar presentations


Presentation on theme: "ANDROID LISTS."— Presentation transcript:

1 ANDROID LISTS

2 Android Lists (Introduction)
Items can be placed in a list from which the user can scroll through the items The selection of a list item might (and often does) start another activity or fragment Or display detail data Adapters manage the data model We connect the list to an array or other data type

3 Adapter Pattern Adapters are just another design pattern
The adapter design pattern makes incompatible things compatible Adapters are structural patterns Intent: Convert the interface of a class into another one Wrap a class with a new interface

4 Arrays as Resources We can create array resources
<string-array> is an array of strings <integer-array> is an array of integers

5 Arrays as Resources (Example)

6 Reading an Array Resource
Remember that getResources() is used to get a resource getStringArray() gets a string resource array getIntArray() gets an integer resource array

7 Reading an Array Resource (Example)
Get the string array named adobe_products and store the result in the String array variable adobe_products Use R.array.array_name String[] adobe_products = getResources().getStringArray( R.array.adobe_products);

8 Creating the ArrayAdapter (1)
The constructor we will use accepts 4 arguments: The first contains a reference to the current context (this) The second contains the resource ID for a layout (R.layout.list_item) The third contains the id of the TextView within the layout to be populated The last contains the array of objects

9 Creating the ArrayAdapter (2)

10 Working with the Lists (Method 1)
Derive an Activity from ListActivity Use this method when implementing a full screen list ListActivity manages the complexities of the list itself Such as providing a default full screen layout It’s possible to create a custom layout though

11 Working with the Lists (Method 2)
The ListView widget is used when you need a custom screen layout There are requirements The layout MUST contain a ListView object

12 Working With Lists (Method 1)

13 The ListView (Introduction)
The ListView is a view group that displays a list of scrollable items The ExpandableListView class supports a grouping of items Items are added using an adapter that pulls content from a source (commonly called the data model) An array (ArrayAdapter) Or database query (CursorAdapter)

14 Referencing the ListView
The getListView method applies to the ListActivity class. It gets the activity’s ListView widget The control is built-in to ListActivity

15 Wiring onItemClick The ListView has an OnItemClickListener

16 Wiring onItemClick (Example)

17 Implementing the ListView
In the layout file, you need to create the ListView itself

18 Implementing the ListView
Next, wire he ListView to the Adapter Note here we are using an inline array rather than a resource


Download ppt "ANDROID LISTS."

Similar presentations


Ads by Google