ListView
public
class
ListView
extends AbsListView
java.lang.Object | |||||
↳ | android.view.View | ||||
↳ | android.view.ViewGroup | ||||
↳ | android.widget.AdapterView<android.widget.ListAdapter> | ||||
↳ | android.widget.AbsListView | ||||
↳ | android.widget.ListView |
Displays a vertically-scrollable collection of views, where each view is positioned
immediatelybelow the previous view in the list. For a more modern, flexible, and performant
approach to displaying lists, use RecyclerView
.
To display a list, you can include a list view in your layout XML file:
<ListView android:id="@+id/list_view" android:layout_width="match_parent" android:layout_height="match_parent" />
A list view is an
adapter view that does not know the details, such as type and contents, of the views it
contains. Instead list view requests views on demand from a ListAdapter
as needed,
such as to display new views as the user scrolls up or down.
In order to display items in the list, call setAdapter(ListAdapter)
to associate an adapter with the list. For a simple example, see the discussion of filling an
adapter view with text in the
Layouts guide.
To display a more custom view for each item in your dataset, implement a ListAdapter.
For example, extend BaseAdapter
and create and configure the view for each data item in
getView(...)
:
private class MyAdapter extends BaseAdapter { // override other abstract methods here @Override public View getView(int position, View convertView, ViewGroup container) { if (convertView == null) { convertView = getLayoutInflater().inflate(R.layout.list_item, container, false); } ((TextView) convertView.findViewById(android.R.id.text1)) .setText(getItem(position)); return convertView; } }
ListView attempts to reuse view objects in order to improve performance and
avoid a lag in response to user scrolls. To take advantage of this feature, check if the
convertView
provided to getView(...)
is null before creating or inflating a new
view object. See
Making ListView Scrolling Smooth for more ways to ensure a smooth user experience.
For a more complete example of creating a custom adapter, see the Custom Choice List sample app.
To specify an action when a user clicks or taps on a single list item, see Handling click events.
To learn how to populate a list view with a CursorAdapter, see the discussion of filling an adapter view with text in the Layouts guide. See Using a Loader to learn how to avoid blocking the main thread when using a cursor.
Note, many examples use ListActivity
or ListFragment
to display a list view. Instead, favor the more flexible approach when writing your own app:
use a more generic Activity subclass or Fragment subclass and add a list view to the layout
or view hierarchy directly. This approach gives you more direct control of the
list view and adapter.
Summary
Nested classes | |
---|---|
class |
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: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. |
Inherited XML attributes | |
---|---|
Inherited constants |
---|
Inherited fields |
---|
Public constructors | |
---|---|
ListView(Context context)
|
|
ListView(Context context, AttributeSet attrs)
|
|
ListView(Context context, AttributeSet attrs, int defStyleAttr)
|
|
ListView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes)
|
Public methods | |
---|---|
void
|
addFooterView(View v, Object data, boolean isSelectable)
Add a fixed view to appear at the bottom of the list. |
void
|
addFooterView(View v)
Add a fixed view to appear at the bottom of the list. |
void
|
addHeaderView(View v, Object data, boolean isSelectable)
Add a fixed view to appear at the top of the list. |
void
|
addHeaderView(View v)
Add a fixed view to appear at the top of the list. |
boolean
|
areFooterDividersEnabled()
|
boolean
|
areHeaderDividersEnabled()
|
boolean
|
dispatchKeyEvent(KeyEvent event)
Dispatch a key event to the next view on the focus path. |
CharSequence
|
getAccessibilityClassName()
Return the class name of this object to be used for accessibility purposes. |
ListAdapter
|
getAdapter()
Returns the adapter currently in use in this ListView. |
long[]
|
getCheckItemIds()
This method was deprecated
in API level 8.
Use |
Drawable
|
getDivider()
Returns the drawable that will be drawn between each item in the list. |
int
|
getDividerHeight()
|
int
|
getFooterViewsCount()
Returns the number of footer views in the list. |
int
|
getHeaderViewsCount()
Returns the number of header views in the list. |
boolean
|
getItemsCanFocus()
|
int
|
getMaxScrollAmount()
|
Drawable
|
getOverscrollFooter()
|
Drawable
|
getOverscrollHeader()
|
boolean
|
isOpaque()
Indicates whether this View is opaque. |
void
|
onInitializeAccessibilityNodeInfoForItem(View view, int position, AccessibilityNodeInfo info)
Initializes an |
boolean
|
onKeyDown(int keyCode, KeyEvent event)
Default implementation of |
boolean
|
onKeyMultiple(int keyCode, int repeatCount, KeyEvent event)
Default implementation of |
boolean
|
onKeyUp(int keyCode, KeyEvent event)
Default implementation of |
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
|
setCacheColorHint(int color)
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. |
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
|
setFooterDividersEnabled(boolean footerDividersEnabled)
Enables or disables the drawing of the divider for footer views. |
void
|
setHeaderDividersEnabled(boolean headerDividersEnabled)
Enables or disables the drawing of the divider for header views. |
void
|
setItemsCanFocus(boolean itemsCanFocus)
Indicates that the views created by the ListAdapter can contain focusable items. |
void
|
setOverscrollFooter(Drawable footer)
Sets the drawable that will be drawn below all other list content. |
void
|
setOverscrollHeader(Drawable header)
Sets the drawable that will be drawn above all other list content. |
void
|
setRemoteViewsAdapter(Intent intent)
Sets up this AbsListView to use a remote views adapter which connects to a RemoteViewsService through the specified intent. |
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
|
smoothScrollByOffset(int offset)
Smoothly scroll to the specified adapter position offset. |
void
|
smoothScrollToPosition(int position)
Smoothly scroll to the specified adapter position. |
Protected methods | |
---|---|
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. |
boolean
|
drawChild(Canvas canvas, View child, long drawingTime)
Draw one child of this View Group. |
void
|
layoutChildren()
Subclasses must override this method to layout their children. |
void
|
onDetachedFromWindow()
This is called when the view is detached from a window. |
void
|
onFinishInflate()
Finalize inflating a view from XML. |
void
|
onFocusChanged(boolean gainFocus, int direction, Rect previouslyFocusedRect)
Called by the view system when the focus state of this view changes. |
void
|
onMeasure(int widthMeasureSpec, int heightMeasureSpec)
Measure the view and its content to determine the measured width and the measured height. |
void
|
onSizeChanged(int w, int h, int oldw, int oldh)
This is called during layout when the size of this view has changed. |
Inherited methods | |
---|---|
XML attributes
android:divider
Drawable or color to draw between list items.
May be a reference to another resource, in the form
"@[+][package:]type/name
" or a theme
attribute in the form
"?[package:]type/name
".
May be a color value, in the form of "#rgb
",
"#argb
", "#rrggbb
", or
"#aarrggbb
".
android:divider
Drawable or color to draw between list items.
May be a reference to another resource, in the form
"@[+][package:]type/name
" or a theme
attribute in the form
"?[package:]type/name
".
May be a color value, in the form of "#rgb
",
"#argb
", "#rrggbb
", or
"#aarrggbb
".
Related methods:
android:dividerHeight
Height of the divider. Will use the intrinsic height of the divider if this is not specified.
May 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), and
mm (millimeters).
android:entries
Reference to an array resource that will populate the ListView. For static content, this is simpler than populating the ListView programmatically.
May be a reference to another resource, in the form
"@[+][package:]type/name
" or a theme
attribute in the form
"?[package:]type/name
".
android:footerDividersEnabled
When set to false, the ListView will not draw the divider before each footer view. The default value is true.
May be a boolean value, such as "true
" or
"false
".
android:headerDividersEnabled
When set to false, the ListView will not draw the divider after each header view. The default value is true.
May be a boolean value, such as "true
" or
"false
".
Public constructors
ListView
public ListView (Context context, AttributeSet attrs)
Parameters | |
---|---|
context |
Context |
attrs |
AttributeSet |
ListView
public ListView (Context context, AttributeSet attrs, int defStyleAttr)
Parameters | |
---|---|
context |
Context |
attrs |
AttributeSet |
defStyleAttr |
int |
ListView
public ListView (Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes)
Parameters | |
---|---|
context |
Context |
attrs |
AttributeSet |
defStyleAttr |
int |
defStyleRes |
int |
Public methods
addFooterView
public void addFooterView (View v, Object data, boolean isSelectable)
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
Build.VERSION_CODES.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
.
Parameters | |
---|---|
v |
View : The view to add. |
data |
Object : Data to associate with this view |
isSelectable |
boolean : true if the footer view can be selected
|
addFooterView
public void addFooterView (View v)
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
Build.VERSION_CODES.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
.
Parameters | |
---|---|
v |
View : The view to add.
|
addHeaderView
public void addHeaderView (View v, Object data, boolean isSelectable)
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
Build.VERSION_CODES.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
.
Parameters | |
---|---|
v |
View : The view to add. |
data |
Object : Data to associate with this view |
isSelectable |
boolean : whether the item is selectable
|
addHeaderView
public void addHeaderView (View v)
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
Build.VERSION_CODES.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
.
Parameters | |
---|---|
v |
View : The view to add.
|
areFooterDividersEnabled
public boolean areFooterDividersEnabled ()
Returns | |
---|---|
boolean |
Whether the drawing of the divider for footer views is enabled |
See also:
areHeaderDividersEnabled
public boolean areHeaderDividersEnabled ()
Returns | |
---|---|
boolean |
Whether the drawing of the divider for header views is enabled |
See also:
dispatchKeyEvent
public boolean dispatchKeyEvent (KeyEvent event)
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.
Parameters | |
---|---|
event |
KeyEvent : The key event to be dispatched. |
Returns | |
---|---|
boolean |
True if the event was handled, false otherwise. |
getAccessibilityClassName
public CharSequence getAccessibilityClassName ()
Return the class name of this object to be used for accessibility purposes.
Subclasses should only override this if they are implementing something that
should be seen as a completely new class of view when used by accessibility,
unrelated to the class it is deriving from. This is used to fill in
AccessibilityNodeInfo.setClassName
.
Returns | |
---|---|
CharSequence |
getAdapter
public ListAdapter getAdapter ()
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
.
Returns | |
---|---|
ListAdapter |
The adapter currently used to display data in this ListView. |
See also:
getCheckItemIds
public long[] getCheckItemIds ()
This method was deprecated
in API level 8.
Use AbsListView.getCheckedItemIds()
instead.
Returns the set of checked items ids. The result is only valid if the
choice mode has not been set to AbsListView.CHOICE_MODE_NONE
.
Returns | |
---|---|
long[] |
A new array which contains the id of each checked item in the list. |
getDivider
public Drawable getDivider ()
Returns the drawable that will be drawn between each item in the list.
Related XML Attributes:
Returns | |
---|---|
Drawable |
the current drawable drawn between list elements This value may be |
getDividerHeight
public int getDividerHeight ()
Returns | |
---|---|
int |
Returns the height of the divider that will be drawn between each item in the list. |
getFooterViewsCount
public int getFooterViewsCount ()
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 | |
---|---|
int |
The number of footer views, 0 in the default implementation. |
getHeaderViewsCount
public int getHeaderViewsCount ()
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.
Returns | |
---|---|
int |
The number of header views, 0 in the default implementation. |
getItemsCanFocus
public boolean getItemsCanFocus ()
Returns | |
---|---|
boolean |
Whether the views created by the ListAdapter can contain focusable items. |
getMaxScrollAmount
public int getMaxScrollAmount ()
Returns | |
---|---|
int |
The maximum amount a list view will scroll in response to an arrow event. |
getOverscrollFooter
public Drawable getOverscrollFooter ()
Returns | |
---|---|
Drawable |
The drawable that will be drawn below all other list content |
getOverscrollHeader
public Drawable getOverscrollHeader ()
Returns | |
---|---|
Drawable |
The drawable that will be drawn above all other list content |
isOpaque
public boolean isOpaque ()
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.
Returns | |
---|---|
boolean |
True if this View is guaranteed to be fully opaque, false otherwise. |
onInitializeAccessibilityNodeInfoForItem
public void onInitializeAccessibilityNodeInfoForItem (View view, int position, AccessibilityNodeInfo info)
Initializes an AccessibilityNodeInfo
with information about a
particular item in the list.
Parameters | |
---|---|
view |
View : View representing the list item. |
position |
int : Position of the list item within the adapter. |
info |
AccessibilityNodeInfo : Node info to populate.
|
onKeyDown
public boolean onKeyDown (int keyCode, KeyEvent event)
Default implementation of KeyEvent.Callback.onKeyDown()
: perform press of the view
when KeyEvent.KEYCODE_DPAD_CENTER
or KeyEvent.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.
Parameters | |
---|---|
keyCode |
int : a key code that represents the button pressed, from
KeyEvent |
event |
KeyEvent : the KeyEvent object that defines the button action
|
Returns | |
---|---|
boolean |
If you handled the event, return true. If you want to allow the event to be handled by the next receiver, return false. |
onKeyMultiple
public boolean onKeyMultiple (int keyCode, int repeatCount, KeyEvent event)
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.
Parameters | |
---|---|
keyCode |
int : A key code that represents the button pressed, from
KeyEvent . |
repeatCount |
int : The number of times the action was made. |
event |
KeyEvent : The KeyEvent object that defines the button action.
|
Returns | |
---|---|
boolean |
If you handled the event, return true. If you want to allow the event to be handled by the next receiver, return false. |
onKeyUp
public boolean onKeyUp (int keyCode, KeyEvent event)
Default implementation of KeyEvent.Callback.onKeyUp()
: perform clicking of the view
when KeyEvent.KEYCODE_DPAD_CENTER
, KeyEvent.KEYCODE_ENTER
or KeyEvent.KEYCODE_SPACE
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.
Parameters | |
---|---|
keyCode |
int : A key code that represents the button pressed, from
KeyEvent . |
event |
KeyEvent : The KeyEvent object that defines the button action.
|
Returns | |
---|---|
boolean |
If you handled the event, return true. If you want to allow the event to be handled by the next receiver, return false. |
removeFooterView
public boolean removeFooterView (View v)
Removes a previously-added footer view.
Parameters | |
---|---|
v |
View : The view to remove |
Returns | |
---|---|
boolean |
true if the view was removed, false if the view was not a footer view |
removeHeaderView
public boolean removeHeaderView (View v)
Removes a previously-added header view.
Parameters | |
---|---|
v |
View : The view to remove |
Returns | |
---|---|
boolean |
true if the view was removed, false if the view was not a header view |
requestChildRectangleOnScreen
public 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. ViewGroup
s overriding this can trust
that:
- child will be a direct child of this group
- rectangle will be in the child's content coordinates
ViewGroup
s overriding this should uphold the contract:
- nothing will change if the rectangle is already visible
- the view port will be scrolled only just enough to make the rectangle visible
Parameters | |
---|---|
child |
View : The direct child making the request. |
rect |
Rect : The rectangle in the child's coordinates the child
wishes to be on the screen. |
immediate |
boolean : True to forbid animated or delayed scrolling,
false otherwise |
Returns | |
---|---|
boolean |
Whether the group scrolled to handle the operation |
setAdapter
public void setAdapter (ListAdapter adapter)
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.
Parameters | |
---|---|
adapter |
ListAdapter : 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. |
See also:
setCacheColorHint
public void setCacheColorHint (int color)
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 View.setBackgroundDrawable(Drawable)
).
Parameters | |
---|---|
color |
int : The background color
|
setDivider
public void setDivider (Drawable divider)
Sets the drawable that will be drawn between each item in the list.
Note: If the drawable does not have an intrinsic
height, you should also call setDividerHeight(int)
.
Related XML Attributes:
Parameters | |
---|---|
divider |
Drawable : the drawable to useThis value may be |
setDividerHeight
public void setDividerHeight (int height)
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)
Parameters | |
---|---|
height |
int : The new height of the divider in pixels.
|
setFooterDividersEnabled
public void setFooterDividersEnabled (boolean footerDividersEnabled)
Enables or disables the drawing of the divider for footer views.
Parameters | |
---|---|
footerDividersEnabled |
boolean : True to draw the footers, false otherwise. |
setHeaderDividersEnabled
public void setHeaderDividersEnabled (boolean headerDividersEnabled)
Enables or disables the drawing of the divider for header views.
Parameters | |
---|---|
headerDividersEnabled |
boolean : True to draw the headers, false otherwise. |
setItemsCanFocus
public void setItemsCanFocus (boolean itemsCanFocus)
Indicates that the views created by the ListAdapter can contain focusable items.
Parameters | |
---|---|
itemsCanFocus |
boolean : true if items can get focus, false otherwise
|
setOverscrollFooter
public void setOverscrollFooter (Drawable footer)
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.
Parameters | |
---|---|
footer |
Drawable : The drawable to use
|
setOverscrollHeader
public void setOverscrollHeader (Drawable header)
Sets the drawable that will be drawn above all other list content. This area can become visible when the user overscrolls the list.
Parameters | |
---|---|
header |
Drawable : The drawable to use
|
setRemoteViewsAdapter
public void setRemoteViewsAdapter (Intent intent)
Sets up this AbsListView to use a remote views adapter which connects to a RemoteViewsService through the specified intent.
Parameters | |
---|---|
intent |
Intent : the intent used to identify the RemoteViewsService for the adapter to connect to.
|
setSelection
public void setSelection (int position)
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.
Parameters | |
---|---|
position |
int : Index (starting at 0) of the data item to be selected.
|
setSelectionAfterHeaderView
public void setSelectionAfterHeaderView ()
setSelectionAfterHeaderView set the selection to be the first list item after the header views.
smoothScrollByOffset
public void smoothScrollByOffset (int offset)
Smoothly scroll to the specified adapter position offset. The view will scroll such that the indicated position is displayed.
Parameters | |
---|---|
offset |
int : The amount to offset from the adapter position to scroll to.
|
smoothScrollToPosition
public void smoothScrollToPosition (int position)
Smoothly scroll to the specified adapter position. The view will scroll such that the indicated position is displayed.
Parameters | |
---|---|
position |
int : Scroll to this adapter position.
|
Protected methods
canAnimate
protected boolean canAnimate ()
Indicates whether the view group has the ability to animate its children after the first layout.
Returns | |
---|---|
boolean |
true if the children can be animated, false otherwise |
dispatchDraw
protected void dispatchDraw (Canvas canvas)
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).
Parameters | |
---|---|
canvas |
Canvas : the canvas on which to draw the view
|
drawChild
protected boolean drawChild (Canvas canvas, View child, long drawingTime)
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.
Parameters | |
---|---|
canvas |
Canvas : The canvas on which to draw the child |
child |
View : Who to draw |
drawingTime |
long : The time at which draw is occurring |
Returns | |
---|---|
boolean |
True if an invalidate() was issued |
layoutChildren
protected void layoutChildren ()
Subclasses must override this method to layout their children.
onDetachedFromWindow
protected void onDetachedFromWindow ()
This is called when the view is detached from a window. At this point it no longer has a surface for drawing.
onFinishInflate
protected void onFinishInflate ()
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.
onFocusChanged
protected void onFocusChanged (boolean gainFocus, int direction, Rect previouslyFocusedRect)
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.
Parameters | |
---|---|
gainFocus |
boolean : True if the View has focus; false otherwise. |
direction |
int : The direction focus has moved when requestFocus()
is called to give this view focus. Values are
View.FOCUS_UP , View.FOCUS_DOWN , View.FOCUS_LEFT ,
View.FOCUS_RIGHT , View.FOCUS_FORWARD , or View.FOCUS_BACKWARD .
It may not always apply, in which case use the default. |
previouslyFocusedRect |
Rect : 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.
|
onMeasure
protected void onMeasure (int widthMeasureSpec, int heightMeasureSpec)
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 overridden 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()
).
Parameters | |
---|---|
widthMeasureSpec |
int : horizontal space requirements as imposed by the parent.
The requirements are encoded with
View.MeasureSpec . |
heightMeasureSpec |
int : vertical space requirements as imposed by the parent.
The requirements are encoded with
View.MeasureSpec . |
onSizeChanged
protected void onSizeChanged (int w, int h, int oldw, int oldh)
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.
Parameters | |
---|---|
w |
int : Current width of this view. |
h |
int : Current height of this view. |
oldw |
int : Old width of this view. |
oldh |
int : Old height of this view.
|
Annotations
Interfaces
- AbsListView.MultiChoiceModeListener
- AbsListView.OnScrollListener
- AbsListView.RecyclerListener
- AbsListView.SelectionBoundsAdjuster
- ActionMenuView.OnMenuItemClickListener
- Adapter
- AdapterView.OnItemClickListener
- AdapterView.OnItemLongClickListener
- AdapterView.OnItemSelectedListener
- Advanceable
- AutoCompleteTextView.OnDismissListener
- AutoCompleteTextView.Validator
- CalendarView.OnDateChangeListener
- Checkable
- Chronometer.OnChronometerTickListener
- CompoundButton.OnCheckedChangeListener
- DatePicker.OnDateChangedListener
- ExpandableListAdapter
- ExpandableListView.OnChildClickListener
- ExpandableListView.OnGroupClickListener
- ExpandableListView.OnGroupCollapseListener
- ExpandableListView.OnGroupExpandListener
- Filter.FilterListener
- Filterable
- FilterQueryProvider
- HeterogeneousExpandableList
- ListAdapter
- MediaController.MediaPlayerControl
- MultiAutoCompleteTextView.Tokenizer
- NumberPicker.Formatter
- NumberPicker.OnScrollListener
- NumberPicker.OnValueChangeListener
- PopupMenu.OnDismissListener
- PopupMenu.OnMenuItemClickListener
- PopupWindow.OnDismissListener
- RadioGroup.OnCheckedChangeListener
- RatingBar.OnRatingBarChangeListener
- RemoteViewsService.RemoteViewsFactory
- SearchView.OnCloseListener
- SearchView.OnQueryTextListener
- SearchView.OnSuggestionListener
- SectionIndexer
- SeekBar.OnSeekBarChangeListener
- ShareActionProvider.OnShareTargetSelectedListener
- SimpleAdapter.ViewBinder
- SimpleCursorAdapter.CursorToStringConverter
- SimpleCursorAdapter.ViewBinder
- SimpleCursorTreeAdapter.ViewBinder
- SlidingDrawer.OnDrawerCloseListener
- SlidingDrawer.OnDrawerOpenListener
- SlidingDrawer.OnDrawerScrollListener
- SpinnerAdapter
- TabHost.OnTabChangeListener
- TabHost.TabContentFactory
- TextView.OnEditorActionListener
- ThemedSpinnerAdapter
- TimePicker.OnTimeChangedListener
- Toolbar.OnMenuItemClickListener
- ViewSwitcher.ViewFactory
- WrapperListAdapter
- ZoomButtonsController.OnZoomListener
Classes
- AbsListView
- AbsListView.LayoutParams
- AbsoluteLayout
- AbsoluteLayout.LayoutParams
- AbsSeekBar
- AbsSpinner
- ActionMenuView
- ActionMenuView.LayoutParams
- AdapterView
- AdapterView.AdapterContextMenuInfo
- AdapterViewAnimator
- AdapterViewFlipper
- AlphabetIndexer
- AnalogClock
- ArrayAdapter
- AutoCompleteTextView
- BaseAdapter
- BaseExpandableListAdapter
- Button
- CalendarView
- CheckBox
- CheckedTextView
- Chronometer
- CompoundButton
- CursorAdapter
- CursorTreeAdapter
- DatePicker
- DialerFilter
- DigitalClock
- EdgeEffect
- EditText
- ExpandableListView
- ExpandableListView.ExpandableListContextMenuInfo
- Filter
- Filter.FilterResults
- FrameLayout
- FrameLayout.LayoutParams
- Gallery
- Gallery.LayoutParams
- GridLayout
- GridLayout.Alignment
- GridLayout.LayoutParams
- GridLayout.Spec
- GridView
- HeaderViewListAdapter
- HorizontalScrollView
- ImageButton
- ImageSwitcher
- ImageView
- LinearLayout
- LinearLayout.LayoutParams
- ListPopupWindow
- ListView
- ListView.FixedViewInfo
- Magnifier
- MediaController
- MultiAutoCompleteTextView
- MultiAutoCompleteTextView.CommaTokenizer
- NumberPicker
- OverScroller
- PopupMenu
- PopupWindow
- ProgressBar
- QuickContactBadge
- RadioButton
- RadioGroup
- RadioGroup.LayoutParams
- RatingBar
- RelativeLayout
- RelativeLayout.LayoutParams
- RemoteViews
- RemoteViewsService
- ResourceCursorAdapter
- ResourceCursorTreeAdapter
- Scroller
- ScrollView
- SearchView
- SeekBar
- ShareActionProvider
- SimpleAdapter
- SimpleCursorAdapter
- SimpleCursorTreeAdapter
- SimpleExpandableListAdapter
- SlidingDrawer
- Space
- Spinner
- StackView
- Switch
- TabHost
- TabHost.TabSpec
- TableLayout
- TableLayout.LayoutParams
- TableRow
- TableRow.LayoutParams
- TabWidget
- TextClock
- TextSwitcher
- TextView
- TextView.SavedState
- TimePicker
- Toast
- ToggleButton
- Toolbar
- Toolbar.LayoutParams
- TwoLineListItem
- VideoView
- ViewAnimator
- ViewFlipper
- ViewSwitcher
- ZoomButton
- ZoomButtonsController
- ZoomControls
Enums
Exceptions