English | Site Directory

Android - An Open Handset Alliance Project

android.widget
public class

android.widget.ListView

java.lang.Object
android.view.View Drawable.Callback KeyEvent.Callback
android.view.ViewGroup ViewManager ViewParent
android.widget.AdapterView
android.widget.AbsListView
android.widget.ListView

A view that shows items in a vertically scrolling list. The items come from the ListAdapter associated with this view.

Note: You cannot use the value wrap_content for the android:layout_height attribute of a ListView in XML if the parent's size is also not strictly specified (for example, if the parent were ScrollView you could not specify wrap_content since it also can be any length. However, you can use wrap_content if the ListView parent has a specific size, such as 100 pixels.

Also see ViewGroup.LayoutParams for layout attributes.

Nested Classes
ListView.OnListViewScrollListener Interface definition for a callback to be invoked when either the number of visible elements change or the index of the first element changes. 
Known Direct Subclasses

Summary

XML Attributes

Attribute name Related methods  
android:entries   Reference to an array resource that will populate the ListView. 
XML Attributes inherited from class android.widget.AbsListView
XML Attributes inherited from class android.view.ViewGroup
XML Attributes inherited from class android.view.View
Constants inherited from class android.widget.AbsListView
Constants inherited from class android.widget.AdapterView
Constants inherited from class android.view.ViewGroup
Constants inherited from class android.view.View

Fields

protected      Drawable  mDivider   
protected      int  mDividerHeight   
Fields inherited from class android.widget.AbsListView
Fields inherited from class android.widget.AdapterView
Fields inherited from class android.view.ViewGroup
Fields inherited from class android.view.View

Public Constructors

          ListView(Context context)
          ListView(Context context, AttributeSet attrs, Map inflateParams)
          ListView(Context context, AttributeSet attrs, Map inflateParams, int defStyle)

Public Methods

        void  addFooterView(View v)
Add a fixed view to appear at the bottom of the list.
        void  addFooterView(View v, Object data, boolean isSelectable)
Add a fixed view to appear at the bottom of the list.
        void  addHeaderView(View v)
Add a fixed view to appear at the top of the list.
        void  addHeaderView(View v, Object data, boolean isSelectable)
Add a fixed view to appear at the top of the list.
        boolean  dispatchKeyEvent(KeyEvent event)
Dispatch a key event to the next view on the focus path.
        void  draw(Canvas canvas)
Manually render this view (and all of its children) to the given Canvas.
        ListAdapter  getAdapter()
        boolean  getItemsCanFocus()
        int  getMaxScrollAmount()
        int  getNumberOfFooterViews()
Gets the number of footer views in the list.
        int  getNumberOfHeaderViews()
Gets the number of header views in the list.
        boolean  onKeyDown(int keyCode, KeyEvent event)
Default implementation of KeyEvent.Callback.onKeyMultiple(): perform press of the view when KEYCODE_DPAD_CENTER or KEYCODE_NEWLINE is released, if the view is enabled and clickable.
        boolean  onKeyMultiple(int keyCode, int repeatCount, KeyEvent event)
Default implementation of KeyEvent.Callback.onKeyMultiple(): always returns false (doesn't handle the event).
        boolean  removeFooterView(View v)
Removes a previously-added footer view.
        boolean  removeHeaderView(View v)
Removes a previously-added header view.
        boolean  requestChildRectangleOnScreen(View child, Rect rect, boolean immediate)
Called when a child of this group wants a particular rectangle to be positioned onto the screen.
        void  setAdapter(ListAdapter adapter)
Sets the data behind this ListView.
        void  setDivider(Drawable divider)
Sets the drawable that will be drawn between each item in the list.
        void  setDividerHeight(int height)
Sets the height of the divider that will be drawn between each item in the list.
        void  setItemsCanFocus(boolean itemsCanFocus)
Indicates that the views created by the ListAdapter can contain focusable items.
        void  setOnListViewScrollListener(OnListViewScrollListener l)
Set the listener that will receive notifications every time the list scrolls.
        void  setSelection(int position)
Sets the currently selected item
        void  setSelectionAfterHeaderView()
setSelectionAfterHeaderView set the selection to be the first list item after the header views.
        void  setSelectionFromTop(int position, int y)
Sets the selected item and positions the selection y pixels from the top edge of the ListView.
        void  setStripes(Drawable[] stripes, int stripeHeight)
        boolean  verifyDrawable(Drawable dr)
If your view subclass is displaying its own Drawable objects, it should override this function and return true for any Drawable it is displaying.

Protected Methods

        boolean  arrowScroll(int direction)
Scrolls to the next or previous item if possible.
        boolean  canAnimate()
Indicates whether the view group has the ability to animate its children after the first layout.
        void  dispatchDraw(Canvas canvas)
Called by draw to draw the child views.
        void  drawDivider(Canvas canvas, Rect bounds, int childIndex)
Draws a divider for the given child in the given bounds.
        void  drawableStateChanged()
This function is called whenever the state of the view changes in such a way that it impacts the state of drawables being shown.
        int  findMotionRow(int y)
Find the row closest to y.
        View  findViewInHeadersOrFooters(ArrayList where, int id)
        View  findViewTagInHeadersOrFooters(ArrayList where, Object tag)
        View  findViewTraversal(int id)
        View