java.lang.Object | |||||
↳ | android.view.View | ||||
↳ | android.view.ViewGroup | ||||
↳ | android.widget.AdapterView<T extends android.widget.Adapter> | ||||
↳ | android.widget.AbsListView | ||||
↳ | android.widget.ListView |
Known Direct Subclasses |
A view that shows items in a vertically scrolling list. The items
come from the ListAdapter
associated with this view.
See the List View guide.
Nested Classes | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
ListView.FixedViewInfo | A class that represents a fixed view in a list, for example a header at the top or a footer at the bottom. |
XML Attributes | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
android:divider | Drawable or color to draw between list items. | ||||||||||
android:dividerHeight | Height of the divider. | ||||||||||
android:entries | Reference to an array resource that will populate the ListView. | ||||||||||
android:footerDividersEnabled | When set to false, the ListView will not draw the divider before each footer view. | ||||||||||
android:headerDividersEnabled | When set to false, the ListView will not draw the divider after each header view. |
[Expand]
Inherited XML Attributes | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class
android.widget.AbsListView
| |||||||||||
From class
android.view.ViewGroup
| |||||||||||
From class
android.view.View
|
[Expand]
Inherited Constants | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class
android.widget.AbsListView
| |||||||||||
From class
android.widget.AdapterView
| |||||||||||
From class
android.view.ViewGroup
| |||||||||||
From class
android.view.View
|
[Expand]
Inherited Fields | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class
android.view.View
|
Public Constructors | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Add a fixed view to appear at the bottom of the list.
| |||||||||||
Add a fixed view to appear at the bottom of the list.
| |||||||||||
Add a fixed view to appear at the top of the list.
| |||||||||||
Add a fixed view to appear at the top of the list.
| |||||||||||
Dispatch a key event to the next view on the focus path.
| |||||||||||
Returns the adapter currently in use in this ListView.
| |||||||||||
This method was deprecated
in API level 8.
Use
getCheckedItemIds() instead.
| |||||||||||
Returns the drawable that will be drawn between each item in the list.
| |||||||||||
Returns the number of footer views in the list.
| |||||||||||
Returns the number of header views in the list.
| |||||||||||
Indicates whether this View is opaque.
| |||||||||||
Initializes an
AccessibilityEvent with information about
this View which is the event source. | |||||||||||
Initializes an
AccessibilityNodeInfo with information about this view. | |||||||||||
Initializes an
AccessibilityNodeInfo with information about a
particular item in the list. | |||||||||||
Default implementation of
KeyEvent.Callback.onKeyDown() : perform press of the view
when KEYCODE_DPAD_CENTER or KEYCODE_ENTER
is released, if the view is enabled and clickable. | |||||||||||
Default implementation of
KeyEvent.Callback.onKeyMultiple() : always returns false (doesn't handle
the event). | |||||||||||
Default implementation of
KeyEvent.Callback.onKeyUp() : perform clicking of the view
when KEYCODE_DPAD_CENTER or
KEYCODE_ENTER is released. | |||||||||||
Removes a previously-added footer view.
| |||||||||||
Removes a previously-added header view.
| |||||||||||
Called when a child of this group wants a particular rectangle to be
positioned onto the screen.
| |||||||||||
Sets the data behind this ListView.
| |||||||||||
When set to a non-zero value, the cache color hint indicates that this list is always drawn
on top of a solid, single-color, opaque background.
| |||||||||||
Sets the drawable that will be drawn between each item in the list.
| |||||||||||
Sets the height of the divider that will be drawn between each item in the list.
| |||||||||||
Enables or disables the drawing of the divider for footer views.
| |||||||||||
Enables or disables the drawing of the divider for header views.
| |||||||||||
Indicates that the views created by the ListAdapter can contain focusable
items.
| |||||||||||
Sets the drawable that will be drawn below all other list content.
| |||||||||||
Sets the drawable that will be drawn above all other list content.
| |||||||||||
Sets up this AbsListView to use a remote views adapter which connects to a RemoteViewsService
through the specified intent.
| |||||||||||
Sets the currently selected item.
| |||||||||||
setSelectionAfterHeaderView set the selection to be the first list item
after the header views.
| |||||||||||
Sets the selected item and positions the selection y pixels from the top edge
of the ListView.
| |||||||||||
Smoothly scroll to the specified adapter position offset.
| |||||||||||
Smoothly scroll to the specified adapter position.
|
Protected Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Indicates whether the view group has the ability to animate its children
after the first layout.
| |||||||||||
Called by draw to draw the child views.
| |||||||||||
Draw one child of this View Group.
| |||||||||||
Subclasses must override this method to layout their children.
| |||||||||||
Finalize inflating a view from XML.
| |||||||||||
Called by the view system when the focus state of this view changes.
| |||||||||||
Measure the view and its content to determine the measured width and the measured height. | |||||||||||
This is called during layout when the size of this view has changed.
|
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class
android.widget.AbsListView
| |||||||||||
From class
android.widget.AdapterView
| |||||||||||
From class
android.view.ViewGroup
| |||||||||||
From class
android.view.View
| |||||||||||
From class
java.lang.Object
| |||||||||||
From interface
android.graphics.drawable.Drawable.Callback
| |||||||||||
From interface
android.text.TextWatcher
| |||||||||||
From interface
android.view.KeyEvent.Callback
| |||||||||||
From interface
android.view.ViewManager
| |||||||||||
From interface
android.view.ViewParent
| |||||||||||
From interface
android.view.ViewTreeObserver.OnGlobalLayoutListener
| |||||||||||
From interface
android.view.ViewTreeObserver.OnTouchModeChangeListener
| |||||||||||
From interface
android.view.accessibility.AccessibilityEventSource
| |||||||||||
From interface
android.widget.Filter.FilterListener
|
Drawable or color to draw between list items.
May be a reference to another resource, in the form "@[+][package:]type:name
"
or to a theme attribute in the form "?[package:][type:]name
".
May be a color value, in the form of "#rgb
", "#argb
",
"#rrggbb
", or "#aarrggbb
".
This corresponds to the global attribute
resource symbol divider
.
Height of the divider. Will use the intrinsic height of the divider if this is not specified.
Must be a dimension value, which is a floating point number appended with a unit such as "14.5sp
".
Available units are: px (pixels), dp (density-independent pixels), sp (scaled pixels based on preferred font size),
in (inches), mm (millimeters).
This may also be a reference to a resource (in the form
"@[package:]type:name
") or
theme attribute (in the form
"?[package:][type:]name
")
containing a value of this type.
This corresponds to the global attribute
resource symbol dividerHeight
.
Reference to an array resource that will populate the ListView. For static content, this is simpler than populating the ListView programmatically.
Must be a reference to another resource, in the form "@[+][package:]type:name
"
or to a theme attribute in the form "?[package:][type:]name
".
This corresponds to the global attribute
resource symbol entries
.
When set to false, the ListView will not draw the divider before each footer view. The default value is true.
Must be a boolean value, either "true
" or "false
".
This may also be a reference to a resource (in the form
"@[package:]type:name
") or
theme attribute (in the form
"?[package:][type:]name
")
containing a value of this type.
This corresponds to the global attribute
resource symbol footerDividersEnabled
.
When set to false, the ListView will not draw the divider after each header view. The default value is true.
Must be a boolean value, either "true
" or "false
".
This may also be a reference to a resource (in the form
"@[package:]type:name
") or
theme attribute (in the form
"?[package:][type:]name
")
containing a value of this type.
This corresponds to the global attribute
resource symbol headerDividersEnabled
.
Add a fixed view to appear at the bottom of the list. If addFooterView is called more than once, the views will appear in the order they were added. Views added using this call can take focus if they want.
Note: When first introduced, this method could only be called before
setting the adapter with setAdapter(ListAdapter)
. Starting with
KITKAT
, this method may be
called at any time. If the ListView's adapter does not extend
HeaderViewListAdapter
, it will be wrapped with a supporting
instance of WrapperListAdapter
.
v | The view to add. |
---|
Add a fixed view to appear at the bottom of the list. If addFooterView is called more than once, the views will appear in the order they were added. Views added using this call can take focus if they want.
Note: When first introduced, this method could only be called before
setting the adapter with setAdapter(ListAdapter)
. Starting with
KITKAT
, this method may be
called at any time. If the ListView's adapter does not extend
HeaderViewListAdapter
, it will be wrapped with a supporting
instance of WrapperListAdapter
.
v | The view to add. |
---|---|
data | Data to associate with this view |
isSelectable | true if the footer view can be selected |
Add a fixed view to appear at the top of the list. If this method is called more than once, the views will appear in the order they were added. Views added using this call can take focus if they want.
Note: When first introduced, this method could only be called before
setting the adapter with setAdapter(ListAdapter)
. Starting with
KITKAT
, this method may be
called at any time. If the ListView's adapter does not extend
HeaderViewListAdapter
, it will be wrapped with a supporting
instance of WrapperListAdapter
.
v | The view to add. |
---|---|
data | Data to associate with this view |
isSelectable | whether the item is selectable |
Add a fixed view to appear at the top of the list. If addHeaderView is called more than once, the views will appear in the order they were added. Views added using this call can take focus if they want.
Note: When first introduced, this method could only be called before
setting the adapter with setAdapter(ListAdapter)
. Starting with
KITKAT
, this method may be
called at any time. If the ListView's adapter does not extend
HeaderViewListAdapter
, it will be wrapped with a supporting
instance of WrapperListAdapter
.
v | The view to add. |
---|
Dispatch a key event to the next view on the focus path. This path runs from the top of the view tree down to the currently focused view. If this view has focus, it will dispatch to itself. Otherwise it will dispatch the next node down the focus path. This method also fires any key listeners.
event | The key event to be dispatched. |
---|
Returns the adapter currently in use in this ListView. The returned adapter
might not be the same adapter passed to setAdapter(ListAdapter)
but
might be a WrapperListAdapter
.
This method was deprecated
in API level 8.
Use getCheckedItemIds()
instead.
Returns the set of checked items ids. The result is only valid if the
choice mode has not been set to CHOICE_MODE_NONE
.
Returns the drawable that will be drawn between each item in the list.
Returns the number of footer views in the list. Footer views are special views at the bottom of the list that should not be recycled during a layout.
Returns the number of header views in the list. Header views are special views at the top of the list that should not be recycled during a layout.
Indicates whether this View is opaque. An opaque View guarantees that it will draw all the pixels overlapping its bounds using a fully opaque color. Subclasses of View should override this method whenever possible to indicate whether an instance is opaque. Opaque Views are treated in a special way by the View hierarchy, possibly allowing it to perform optimizations during invalidate/draw passes.
Initializes an AccessibilityEvent
with information about
this View which is the event source. In other words, the source of
an accessibility event is the view whose state change triggered firing
the event.
Example: Setting the password property of an event in addition to properties set by the super implementation:
public void onInitializeAccessibilityEvent(AccessibilityEvent event) { super.onInitializeAccessibilityEvent(event); event.setPassword(true); }
If an View.AccessibilityDelegate
has been specified via calling
setAccessibilityDelegate(AccessibilityDelegate)
its
onInitializeAccessibilityEvent(View, AccessibilityEvent)
is responsible for handling this call.
Note: Always call the super implementation before adding information to the event, in case the default implementation has basic information to add.
event | The event to initialize. |
---|
Initializes an AccessibilityNodeInfo
with information about this view.
The base implementation sets:
setParent(View)
,setBoundsInParent(Rect)
,setBoundsInScreen(Rect)
,setPackageName(CharSequence)
,setClassName(CharSequence)
,setContentDescription(CharSequence)
,setEnabled(boolean)
,setClickable(boolean)
,setFocusable(boolean)
,setFocused(boolean)
,setLongClickable(boolean)
,setSelected(boolean)
,Subclasses should override this method, call the super implementation, and set additional attributes.
If an View.AccessibilityDelegate
has been specified via calling
setAccessibilityDelegate(AccessibilityDelegate)
its
onInitializeAccessibilityNodeInfo(View, AccessibilityNodeInfo)
is responsible for handling this call.
info | The instance to initialize. |
---|
Initializes an AccessibilityNodeInfo
with information about a
particular item in the list.
view | View representing the list item. |
---|---|
position | Position of the list item within the adapter. |
info | Node info to populate. |
Default implementation of KeyEvent.Callback.onKeyDown()
: perform press of the view
when KEYCODE_DPAD_CENTER
or KEYCODE_ENTER
is released, if the view is enabled and clickable.
Key presses in software keyboards will generally NOT trigger this listener, although some may elect to do so in some situations. Do not rely on this to catch software key presses.
keyCode | A key code that represents the button pressed, from
KeyEvent . |
---|---|
event | The KeyEvent object that defines the button action. |
Default implementation of KeyEvent.Callback.onKeyMultiple()
: always returns false (doesn't handle
the event).
Key presses in software keyboards will generally NOT trigger this listener, although some may elect to do so in some situations. Do not rely on this to catch software key presses.
keyCode | A key code that represents the button pressed, from
KeyEvent . |
---|---|
repeatCount | The number of times the action was made. |
event | The KeyEvent object that defines the button action. |
Default implementation of KeyEvent.Callback.onKeyUp()
: perform clicking of the view
when KEYCODE_DPAD_CENTER
or
KEYCODE_ENTER
is released.
Key presses in software keyboards will generally NOT trigger this listener, although some may elect to do so in some situations. Do not rely on this to catch software key presses.
keyCode | A key code that represents the button pressed, from
KeyEvent . |
---|---|
event | The KeyEvent object that defines the button action. |
Removes a previously-added footer view.
v | The view to remove |
---|
Removes a previously-added header view.
v | The view to remove |
---|
Called when a child of this group wants a particular rectangle to be
positioned onto the screen. ViewGroup
s overriding this can trust
that:
ViewGroup
s overriding this should uphold the contract:
child | The direct child making the request. |
---|---|
rect | The rectangle in the child's coordinates the child wishes to be on the screen. |
immediate | True to forbid animated or delayed scrolling, false otherwise |
Sets the data behind this ListView.
The adapter passed to this method may be wrapped by a WrapperListAdapter
,
depending on the ListView features currently in use. For instance, adding
headers and/or footers will cause the adapter to be wrapped.
adapter | The ListAdapter which is responsible for maintaining the data backing this list and for producing a view to represent an item in that data set. |
---|
When set to a non-zero value, the cache color hint indicates that this list is always drawn
on top of a solid, single-color, opaque background.
Zero means that what's behind this object is translucent (non solid) or is not made of a
single color. This hint will not affect any existing background drawable set on this view (
typically set via setBackgroundDrawable(Drawable)
).
color | The background color |
---|
Sets the drawable that will be drawn between each item in the list. If the drawable does
not have an intrinsic height, you should also call setDividerHeight(int)
divider | The drawable to use. |
---|
Sets the height of the divider that will be drawn between each item in the list. Calling
this will override the intrinsic height as set by setDivider(Drawable)
height | The new height of the divider in pixels. |
---|
Enables or disables the drawing of the divider for footer views.
footerDividersEnabled | True to draw the footers, false otherwise. |
---|
Enables or disables the drawing of the divider for header views.
headerDividersEnabled | True to draw the headers, false otherwise. |
---|
Indicates that the views created by the ListAdapter can contain focusable items.
itemsCanFocus | true if items can get focus, false otherwise |
---|
Sets the drawable that will be drawn below all other list content. This area can become visible when the user overscrolls the list, or when the list's content does not fully fill the container area.
footer | The drawable to use |
---|
Sets the drawable that will be drawn above all other list content. This area can become visible when the user overscrolls the list.
header | The drawable to use |
---|
Sets up this AbsListView to use a remote views adapter which connects to a RemoteViewsService through the specified intent.
intent | the intent used to identify the RemoteViewsService for the adapter to connect to. |
---|
Sets the currently selected item. If in touch mode, the item will not be selected but it will still be positioned appropriately. If the specified selection position is less than 0, then the item at position 0 will be selected.
position | Index (starting at 0) of the data item to be selected. |
---|
setSelectionAfterHeaderView set the selection to be the first list item after the header views.
Sets the selected item and positions the selection y pixels from the top edge of the ListView. (If in touch mode, the item will not be selected but it will still be positioned appropriately.)
position | Index (starting at 0) of the data item to be selected. |
---|---|
y | The distance from the top edge of the ListView (plus padding) that the item will be positioned. |
Smoothly scroll to the specified adapter position offset. The view will scroll such that the indicated position is displayed.
offset | The amount to offset from the adapter position to scroll to. |
---|
Smoothly scroll to the specified adapter position. The view will scroll such that the indicated position is displayed.
position | Scroll to this adapter position. |
---|
Indicates whether the view group has the ability to animate its children after the first layout.
Called by draw to draw the child views. This may be overridden by derived classes to gain control just before its children are drawn (but after its own view has been drawn).
canvas | the canvas on which to draw the view |
---|
Draw one child of this View Group. This method is responsible for getting the canvas in the right state. This includes clipping, translating so that the child's scrolled origin is at 0, 0, and applying any animation transformations.
canvas | The canvas on which to draw the child |
---|---|
child | Who to draw |
drawingTime | The time at which draw is occurring |
id | the id of the view to be found |
---|
tag | the tag of the view to be found |
---|
Subclasses must override this method to layout their children.
Finalize inflating a view from XML. This is called as the last phase of inflation, after all child views have been added.
Even if the subclass overrides onFinishInflate, they should always be sure to call the super method, so that we get called.
Called by the view system when the focus state of this view changes. When the focus change event is caused by directional navigation, direction and previouslyFocusedRect provide insight into where the focus is coming from. When overriding, be sure to call up through to the super class so that the standard focus handling will occur.
gainFocus | True if the View has focus; false otherwise. |
---|---|
direction | The direction focus has moved when requestFocus()
is called to give this view focus. Values are
FOCUS_UP , FOCUS_DOWN , FOCUS_LEFT ,
FOCUS_RIGHT , FOCUS_FORWARD , or FOCUS_BACKWARD .
It may not always apply, in which case use the default. |
previouslyFocusedRect | The rectangle, in this view's coordinate
system, of the previously focused view. If applicable, this will be
passed in as finer grained information about where the focus is coming
from (in addition to direction). Will be null otherwise.
|
Measure the view and its content to determine the measured width and the
measured height. This method is invoked by measure(int, int)
and
should be overriden by subclasses to provide accurate and efficient
measurement of their contents.
CONTRACT: When overriding this method, you
must call setMeasuredDimension(int, int)
to store the
measured width and height of this view. Failure to do so will trigger an
IllegalStateException
, thrown by
measure(int, int)
. Calling the superclass'
onMeasure(int, int)
is a valid use.
The base class implementation of measure defaults to the background size,
unless a larger size is allowed by the MeasureSpec. Subclasses should
override onMeasure(int, int)
to provide better measurements of
their content.
If this method is overridden, it is the subclass's responsibility to make
sure the measured height and width are at least the view's minimum height
and width (getSuggestedMinimumHeight()
and
getSuggestedMinimumWidth()
).
widthMeasureSpec | horizontal space requirements as imposed by the parent.
The requirements are encoded with
View.MeasureSpec . |
---|---|
heightMeasureSpec | vertical space requirements as imposed by the parent.
The requirements are encoded with
View.MeasureSpec . |
This is called during layout when the size of this view has changed. If you were just added to the view hierarchy, you're called with the old values of 0.
w | Current width of this view. |
---|---|
h | Current height of this view. |
oldw | Old width of this view. |
oldh | Old height of this view. |