Android
android.widget
public abstract class

android.widget.AdapterView<T extends android.widget.Adapter>

java.lang.Object
android.view.View Drawable.Callback KeyEvent.Callback
android.view.ViewGroup ViewManager ViewParent
android.widget.AdapterView<T extends android.widget.Adapter>

An AdapterView is a view whose children are determined by an Adapter.

See ListView, GridView, Spinner and Gallery for commonly used subclasses of AdapterView.

Nested Classes
AdapterView.AdapterContextMenuInfo Extra menu information provided to the onCreateContextMenu(ContextMenu, View, ContextMenuInfo) callback when a context menu is brought up for this AdapterView. 
AdapterView.OnItemClickListener Interface definition for a callback to be invoked when an item in this AdapterView has been clicked. 
AdapterView.OnItemLongClickListener Interface definition for a callback to be invoked when an item in this view has been clicked and held. 
AdapterView.OnItemSelectedListener Interface definition for a callback to be invoked when an item in this view has been selected. 
Known Direct Subclasses
Known Indirect Subclasses

Summary

XML Attributes inherited from class android.view.ViewGroup
XML Attributes inherited from class android.view.View

Constants

      Value  
int  ITEM_VIEW_TYPE_HEADER_OR_FOOTER  The item view type returned by getItemViewType(int) when the item is a header or footer.  -2  0xfffffffe 
int  ITEM_VIEW_TYPE_IGNORE  The item view type returned by getItemViewType(int) when the adapter does not want the item's view recycled.  -1  0xffffffff 
Constants inherited from class android.view.ViewGroup
Constants inherited from class android.view.View

Fields

public  static    int  INVALID_POSITION  Represents an invalid position. 
public  static    long  INVALID_ROW_ID  Represents an empty or invalid row id  
Fields inherited from class android.view.ViewGroup
Fields inherited from class android.view.View

Public Constructors

            AdapterView(Context context)
            AdapterView(Context context, AttributeSet attrs)
            AdapterView(Context context, AttributeSet attrs, int defStyle)

Public Methods

          void  addView(View child, int index)
This method is not supported and throws an UnsupportedOperationException when called.
          void  addView(View child, ViewGroup.LayoutParams params)
This method is not supported and throws an UnsupportedOperationException when called.
          void  addView(View child, int index, ViewGroup.LayoutParams params)
This method is not supported and throws an UnsupportedOperationException when called.
          void  addView(View child)
This method is not supported and throws an UnsupportedOperationException when called.
abstract          getAdapter()
Returns the adapter currently associated with this widget.
          int  getCount()
          View  getEmptyView()
When the current adapter is empty, the AdapterView can display a special view call the empty view.
          int  getFirstVisiblePosition()
Returns the position within the adapter's data set for the first item displayed on screen.
          Object  getItemAtPosition(int position)
Gets the data associated with the specified position in the list.
          long  getItemIdAtPosition(int position)
          int  getLastVisiblePosition()
Returns the position within the adapter's data set for the last item displayed on screen.
    final      AdapterView.OnItemClickListener  getOnItemClickListener()
    final      AdapterView.OnItemLongClickListener  getOnItemLongClickListener()
    final      AdapterView.OnItemSelectedListener  getOnItemSelectedListener()
          int  getPositionForView(View view)
Get the position within the adapter's data set for the view, where view is a an adapter item or a descendant of an adapter item.
          Object  getSelectedItem()
          long  getSelectedItemId()
          int  getSelectedItemPosition()
Return the position of the currently selected item within the adapter's data set
abstract          View  getSelectedView()
          boolean  performItemClick(View view, int position, long id)
Call the OnItemClickListener, if it is defined.
          void  removeAllViews()
This method is not supported and throws an UnsupportedOperationException when called.
          void  removeView(View child)
This method is not supported and throws an UnsupportedOperationException when called.
          void  removeViewAt(int index)
This method is not supported and throws an UnsupportedOperationException when called.
abstract          void  setAdapter(T adapter)
Sets the adapter that provides the data and the views to represent the data in this widget.
          void  setEmptyView(View emptyView)
Sets the view to show if the adapter is empty
          void  setFocusable(boolean focusable)
Set whether this view can receive the focus.
          void  setFocusableInTouchMode(boolean focusable)
Set whether this view can receive focus while in touch mode.
          void  setOnClickListener(View.OnClickListener l)
Register a callback to be invoked when this view is clicked.
          void  setOnItemClickListener(AdapterView.OnItemClickListener listener)
Register a callback to be invoked when an item in this AdapterView has been clicked.
          void  setOnItemLongClickListener(AdapterView.OnItemLongClickListener listener)
Register a callback to be invoked when an item in this AdapterView has been clicked and held
          void  setOnItemSelectedListener(AdapterView.OnItemSelectedListener listener)
Register a callback to be invoked when an item in this AdapterView has been selected.
abstract          void  setSelection(int position)
Sets the currently selected item

Protected Methods

          boolean  canAnimate()
Indicates whether the view group has the ability to animate its children after the first layout.
          void  dispatchRestoreInstanceState(SparseArray<Parcelable> container)
Override to prevent thawing of any views created by the adapter.
          void  dispatchSaveInstanceState(SparseArray<Parcelable> container)
Override to prevent freezing of any views created by the adapter.
          void  onLayout(boolean changed, int left, int top, int right, int bottom)
Called from layout when this view should assign a size and position to each of its children.
Methods inherited from class android.view.ViewGroup
Methods inherited from class android.view.View
Methods inherited from class java.lang.Object
Methods inherited from interface android.graphics.drawable.Drawable.Callback
Methods inherited from interface android.view.KeyEvent.Callback
Methods inherited from interface android.view.ViewManager
Methods inherited from interface android.view.ViewParent

Details

Constants

public static final int ITEM_VIEW_TYPE_HEADER_OR_FOOTER

The item view type returned by getItemViewType(int) when the item is a header or footer.
Constant Value: -2 (0xfffffffe)

public static final int ITEM_VIEW_TYPE_IGNORE

The item view type returned by getItemViewType(int) when the adapter does not want the item's view recycled.
Constant Value: -1 (0xffffffff)

Fields

public static int INVALID_POSITION

Represents an invalid position. All valid positions are in the range 0 to 1 less than the number of items in the current adapter.

public static long INVALID_ROW_ID

Represents an empty or invalid row id

Public Constructors

public AdapterView(Context context)

public AdapterView(Context context, AttributeSet attrs)

public AdapterView(Context context, AttributeSet attrs, int defStyle)

Public Methods

public void addView(View child, int index)

This method is not supported and throws an UnsupportedOperationException when called.

Parameters

child Ignored.
index Ignored.

Throws

UnsupportedOperationException Every time this method is invoked.

public void addView(View child, ViewGroup.LayoutParams params)

This method is not supported and throws an UnsupportedOperationException when called.

Parameters

child Ignored.
params Ignored.

Throws

UnsupportedOperationException Every time this method is invoked.

public void addView(View child, int index, ViewGroup.LayoutParams params)

This method is not supported and throws an UnsupportedOperationException when called.

Parameters

child Ignored.
index Ignored.
params Ignored.

Throws

UnsupportedOperationException Every time this method is invoked.

public void addView(View child)

This method is not supported and throws an UnsupportedOperationException when called.

Parameters

child Ignored.

Throws

UnsupportedOperationException Every time this method is invoked.

public abstract T getAdapter()

Returns the adapter currently associated with this widget.

Returns

  • The adapter used to provide this view's content.

public int getCount()

Returns

  • The number of items owned by the Adapter associated with this AdapterView. (This is the number of data items, which may be larger than the number of visible view.)

public View getEmptyView()

When the current adapter is empty, the AdapterView can display a special view call the empty view. The empty view is used to provide feedback to the user that no data is available in this AdapterView.

Returns

  • The view to show if the adapter is empty.

public int getFirstVisiblePosition()

Returns the position within the adapter's data set for the first item displayed on screen.

Returns

  • The position within the adapter's data set

public Object getItemAtPosition(int position)

Gets the data associated with the specified position in the list.

Parameters

position Which data to get

Returns

  • The data associated with the specified position in the list

public long getItemIdAtPosition(int position)

public int getLastVisiblePosition()

Returns the position within the adapter's data set for the last item displayed on screen.

Returns

  • The position within the adapter's data set

public final AdapterView.OnItemClickListener getOnItemClickListener()

Returns

  • The callback to be invoked with an item in this AdapterView has been clicked, or null id no callback has been set.

public final AdapterView.OnItemLongClickListener getOnItemLongClickListener()

Returns

  • The callback to be invoked with an item in this AdapterView has been clicked and held, or null id no callback as been set.

public final AdapterView.OnItemSelectedListener getOnItemSelectedListener()

public int getPositionForView(View view)

Get the position within the adapter's data set for the view, where view is a an adapter item or a descendant of an adapter item.

Parameters

view an adapter item, or a descendant of an adapter item. This must be visible in this AdapterView at the time of the call.

Returns

  • the position within the adapter's data set of the view, or INVALID_POSITION if the view does not correspond to a list item (or it is not currently visible).

public Object getSelectedItem()

Returns

  • The data corresponding to the currently selected item, or null if there is nothing selected.

public long getSelectedItemId()

Returns

  • The id corresponding to the currently selected item, or INVALID_ROW_ID if nothing is selected.

public int getSelectedItemPosition()

Return the position of the currently selected item within the adapter's data set

Returns

  • int Position (starting at 0), or INVALID_POSITION if there is nothing selected.

public abstract View getSelectedView()

Returns

  • The view corresponding to the currently selected item, or null if nothing is selected

public boolean performItemClick(View view, int position, long id)

Call the OnItemClickListener, if it is defined.

Parameters

view The view within the AdapterView that was clicked.
position The position of the view in the adapter.
id The row id of the item that was clicked.

Returns

  • True if there was an assigned OnItemClickListener that was called, false otherwise is returned.

public void removeAllViews()

This method is not supported and throws an UnsupportedOperationException when called.

Throws

UnsupportedOperationException Every time this method is invoked.

public void removeView(View child)

This method is not supported and throws an UnsupportedOperationException when called.

Parameters

child Ignored.

Throws

UnsupportedOperationException Every time this method is invoked.

public void removeViewAt(int index)

This method is not supported and throws an UnsupportedOperationException when called.

Parameters

index Ignored.

Throws

UnsupportedOperationException Every time this method is invoked.

public abstract void setAdapter(T adapter)

Sets the adapter that provides the data and the views to represent the data in this widget.

Parameters

adapter The adapter to use to create this view's content.

public void setEmptyView(View emptyView)

Sets the view to show if the adapter is empty

public void setFocusable(boolean focusable)

Set whether this view can receive the focus. Setting this to false will also ensure that this view is not focusable in touch mode.

Parameters

focusable If true, this view can receive the focus.

public void setFocusableInTouchMode(boolean focusable)

Set whether this view can receive focus while in touch mode. Setting this to true will also ensure that this view is focusable.

Parameters

focusable If true, this view can receive the focus while in touch mode.

public void setOnClickListener(View.OnClickListener l)

Register a callback to be invoked when this view is clicked. If this view is not clickable, it becomes clickable.

Parameters

l The callback that will run

public void setOnItemClickListener(AdapterView.OnItemClickListener listener)

Register a callback to be invoked when an item in this AdapterView has been clicked.

Parameters

listener The callback that will be invoked.

public void setOnItemLongClickListener(AdapterView.OnItemLongClickListener listener)

Register a callback to be invoked when an item in this AdapterView has been clicked and held

Parameters

listener The callback that will run

public void setOnItemSelectedListener(AdapterView.OnItemSelectedListener listener)

Register a callback to be invoked when an item in this AdapterView has been selected.

Parameters

listener The callback that will run

public abstract void setSelection(int position)

Sets the currently selected item

Parameters

position Index (starting at 0) of the data item to be selected.

Protected Methods

protected boolean canAnimate()

Indicates whether the view group has the ability to animate its children after the first layout.

Returns

  • true if the children can be animated, false otherwise

protected void dispatchRestoreInstanceState(SparseArray<Parcelable> container)

Override to prevent thawing of any views created by the adapter.

Parameters

container The SparseArray which holds previously saved state.

protected void dispatchSaveInstanceState(SparseArray<Parcelable> container)

Override to prevent freezing of any views created by the adapter.

Parameters

container The SparseArray in which to save the view's state.

protected void onLayout(boolean changed, int left, int top, int right, int bottom)

Called from layout when this view should assign a size and position to each of its children. Derived classes with children should override this method and call layout on each of their their children.

Parameters

changed This is a new size or position for this view
left Left position, relative to parent
top Top position, relative to parent
right Right position, relative to parent
bottom Bottom position, relative to parent
Copyright 2007 Google Inc. Build 0.9_r1-98467 - 14 Aug 2008 18:56