Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
63 views

List View

This document discusses views and adapters in Android. It explains that views draw objects on screen and view groups define layouts. AdapterViews like ListView use adapters to link data to views. Adapters populate layouts with data and handle selections. Common adapters include array and cursor adapters. Lists use adapters to display string arrays, databases or other data sources. ListActivity simplifies using ListView. Item clicks can be handled with listeners. Custom views override adapter getView methods. Dynamic items are added by notifying the adapter of changes.

Uploaded by

Mina Fawzy
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
63 views

List View

This document discusses views and adapters in Android. It explains that views draw objects on screen and view groups define layouts. AdapterViews like ListView use adapters to link data to views. Adapters populate layouts with data and handle selections. Common adapters include array and cursor adapters. Lists use adapters to display string arrays, databases or other data sources. ListActivity simplifies using ListView. Item clicks can be handled with listeners. Custom views override adapter getView methods. Dynamic items are added by notifying the adapter of changes.

Uploaded by

Mina Fawzy
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 12

Lecture 10

LIST VIEW

UI Overview
A View is an object that draws something on the screen that the user can interact with. A View Group is an object that holds other View (and ViewGroup) objects in order to define the layout of the interface. LinearLayout and RelativeLayout are typical examples

Layout with Adapters

Data Adapters
Android framework for providing linking mechanism between raw data and view objects

AdapterView Class
A subclass of ViewGroup whose child Views are determined by an Adapter Gallery, ListView, and Spinner are examples of AdapterView

AdapterView objects have two main responsibilities:


Filling the layout with data & Handling user selections

Adapters and Data Sources


Adapters: Array Adapter Common methods: add() , clear(), addAll() Cursor Adapter SimpleArrayAdapter Custom Adapter Data sources could be String Array written in Java String Array Resource Database or content provider ..

ListActivity
ListActivity class can be used if your activity only holds ListView. It does not require assignment to a layout via the setContentView() method

In this case you can directly call the methods such as


setListAdapter(adapter);

Responding to Item Selection


lv.setOnItemClickListener( new AdapterView.OnItemClickListener() {

public void onItemClick(


AdapterView<?> arg0, View arg1, int position,long id) { Toast.makeText(getApplicationContext(), "Item " + position +" Selected", Toast.LENGTH_SHORT ) .show(); } });

ListView Demo

Creating Custom List Views


Implement your own adapter Override getView method

Adding Items to the list dynamically


items.add(newItem); adapter.notifyDataSetChanged();

For More About Adapters


http://www.vogella.com/articles/AndroidListView/article.html http://www.androidhive.info/2013/07/android-expandable-list-view-tutorial/

You might also like