English | Site Directory

Android - An Open Handset Alliance Project

android.widget
public interface

android.widget.Adapter

android.widget.Adapter

An Adapter object acts as a bridge between an AdapterView and the underlying data for that view. The Adapter provides access to the data items. The Adapter is also responsible for making a View for each item in the data set.

Known Indirect Subclasses

Summary

Constants

      Value  
int  NO_SELECTION    -2147483648  0x80000000 

Public Methods

        int  getCount()
How many items are in the data set represented by this Adapter.
        Object  getItem(int position)
Get the data item associated with the specified position in the data set.
        long  getItemId(int position)
Get the row id associated with the specified position in the list.
        int  getNewSelectionForKey(int currentSelection, int keyCode, KeyEvent event)
Given a keyboard key, let the adapter suggest the position in the data set to be made the new selected item.
        View  getView(int position, View convertView, ViewGroup parent)
Get a View that displays the data at the specified position in the data set.
        void  registerDataSetObserver(DataSetObserver observer)
Register an observer that is called when changes happen to the data used by this adapter.
        boolean  stableIds()
Indicated whether the item ids are stable across changes to the underlying data.
        void  unregisterDataSetObserver(DataSetObserver observer)
Unregister an observer that has previously been registered with this adapter via registerDataSetObserver(DataSetObserver).

Details

Constants

public static final int NO_SELECTION

Constant Value: -2147483648 (0x80000000)

Public Methods

public int getCount()

How many items are in the data set represented by this Adapter.

Returns

  • Count of items.

public Object getItem(int position)

Get the data item associated with the specified position in the data set.

Parameters

position Position of the item whose data we want within the adapter's data set.

Returns

  • The data at the specified position.

public long getItemId(int position)

Get the row id associated with the specified position in the list.

Parameters

position The position of the item within the adapter's data set whose row id we want.

Returns

  • The id of the item at the specified position.

public int getNewSelectionForKey(int currentSelection, int keyCode, KeyEvent event)

Given a keyboard key, let the adapter suggest the position in the data set to be made the new selected item. Return NO_SELECTION to indicate no appropriate key (for example, the user pressed the back button, or a subclass does not support this feature).

Parameters

currentSelection the position of the currently selected item. Note that the index can be less than zero or greater than the number of items in the data underlying this Adapter, indicating the selection is on a header or footer item.
keyCode the keyCode for the event
event the full key event structure

Returns

  • The position in the data set to be made the new selected item if a match was found, or NO_SELECTION if there was not a match

public View getView(int position, View convertView, ViewGroup parent)

Get a View that displays the data at the specified position in the data set. You can either create a View manually or inflate it from an XML layout file. When the View is inflated, the parent View (GridView, ListView...) will apply default layout parameters unless you use inflate(int, android.view.ViewGroup, boolean, java.util.Map) to specify a root view and to prevent attachment to the root.

Parameters

position The position of the item within the adapter's data set of the item whose view we want.
convertView The old view to reuse, if possible. Note: You should check that this view is non-null and of an appropriate type before using. If it is not possible to convert this view to display the correct data, this method can create a new view.
parent The parent that this view will eventually be attached to

Returns

  • A View corresponding to the data at the specified position.

public void registerDataSetObserver(DataSetObserver observer)

Register an observer that is called when changes happen to the data used by this adapter.

Parameters

observer the object that gets notified when the data set changes.

public boolean stableIds()

Indicated whether the item ids are stable across changes to the underlying data.

Returns

  • True if the same id always refers to the same object.

public void unregisterDataSetObserver(DataSetObserver observer)

Unregister an observer that has previously been registered with this adapter via registerDataSetObserver(DataSetObserver).

Parameters

observer the object to unregister.
Build m5-rc15i - 10 Jun 2008 13:54