Class ListView
- All Implemented Interfaces:
Drawable.Callback
,ViewManager
,ViewParent
,Filter.FilterListener
- Direct Known Subclasses:
DropDownListView
,ExpandableListView
Displays a vertically-scrollable collection of views, where each view is positioned
immediately below the previous view in the list. For a more modern, flexible, and performant
approach to displaying lists, use
invalid reference
RecyclerView
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 adapter)
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.
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.
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
A class that represents a fixed view in a list, for example a header at the top or a footer at the bottom.Nested classes/interfaces inherited from class icyllis.modernui.widget.AbsListView
AbsListView.LayoutParams, AbsListView.MultiChoiceModeListener, AbsListView.OnScrollListener, AbsListView.RecyclerListener, AbsListView.SelectionBoundsAdjuster
Nested classes/interfaces inherited from class icyllis.modernui.widget.AdapterView
AdapterView.AdapterContextMenuInfo, AdapterView.OnItemClickListener, AdapterView.OnItemLongClickListener, AdapterView.OnItemSelectedListener
Nested classes/interfaces inherited from class icyllis.modernui.view.ViewGroup
ViewGroup.MarginLayoutParams
Nested classes/interfaces inherited from class icyllis.modernui.view.View
View.DragShadow, View.Focusable, View.FocusableMode, View.FocusDirection, View.FocusRealDirection, View.LayoutDir, View.NestedScrollType, View.OnAttachStateChangeListener, View.OnClickListener, View.OnContextClickListener, View.OnCreateContextMenuListener, View.OnDragListener, View.OnFocusChangeListener, View.OnGenericMotionListener, View.OnHoverListener, View.OnKeyListener, View.OnLayoutChangeListener, View.OnLongClickListener, View.OnScrollChangeListener, View.OnTouchListener, View.ResolvedLayoutDir, View.ScrollAxis, View.ScrollBarStyle, View.ScrollIndicators, View.TextAlignment, View.Visibility
-
Field Summary
Fields inherited from class icyllis.modernui.widget.AbsListView
CHOICE_MODE_MULTIPLE, CHOICE_MODE_MULTIPLE_MODAL, CHOICE_MODE_NONE, CHOICE_MODE_SINGLE, TRANSCRIPT_MODE_ALWAYS_SCROLL, TRANSCRIPT_MODE_DISABLED, TRANSCRIPT_MODE_NORMAL
Fields inherited from class icyllis.modernui.widget.AdapterView
INVALID_POSITION, INVALID_ROW_ID, ITEM_VIEW_TYPE_HEADER_OR_FOOTER, ITEM_VIEW_TYPE_IGNORE
Fields inherited from class icyllis.modernui.view.ViewGroup
CLIP_TO_PADDING_MASK, FLAG_DISALLOW_INTERCEPT, FOCUS_AFTER_DESCENDANTS, FOCUS_BEFORE_DESCENDANTS, FOCUS_BLOCK_DESCENDANTS
Fields inherited from class icyllis.modernui.view.View
ALPHA, BOTTOM, EMPTY_STATE_SET, ENABLED_FOCUSED_SELECTED_STATE_SET, ENABLED_FOCUSED_SELECTED_WINDOW_FOCUSED_STATE_SET, ENABLED_FOCUSED_STATE_SET, ENABLED_FOCUSED_WINDOW_FOCUSED_STATE_SET, ENABLED_SELECTED_STATE_SET, ENABLED_SELECTED_WINDOW_FOCUSED_STATE_SET, ENABLED_STATE_SET, ENABLED_WINDOW_FOCUSED_STATE_SET, FOCUS_BACKWARD, FOCUS_DOWN, FOCUS_FORWARD, FOCUS_LEFT, FOCUS_RIGHT, FOCUS_UP, FOCUSABLE, FOCUSABLE_AUTO, FOCUSABLES_ALL, FOCUSABLES_TOUCH_MODE, FOCUSED_SELECTED_STATE_SET, FOCUSED_SELECTED_WINDOW_FOCUSED_STATE_SET, FOCUSED_STATE_SET, FOCUSED_WINDOW_FOCUSED_STATE_SET, GONE, HAPTIC_FEEDBACK_ENABLED, INVISIBLE, LAYOUT_DIRECTION_INHERIT, LAYOUT_DIRECTION_LOCALE, LAYOUT_DIRECTION_LTR, LAYOUT_DIRECTION_RTL, LAYOUT_DIRECTION_UNDEFINED, LEFT, MEASURED_HEIGHT_STATE_SHIFT, MEASURED_SIZE_MASK, MEASURED_STATE_MASK, MEASURED_STATE_TOO_SMALL, mPaddingBottom, mPaddingLeft, mPaddingRight, mPaddingTop, mScrollX, mScrollY, NO_ID, NOT_FOCUSABLE, OVER_SCROLL_ALWAYS, OVER_SCROLL_IF_CONTENT_SCROLLS, OVER_SCROLL_NEVER, PRESSED_ENABLED_FOCUSED_SELECTED_STATE_SET, PRESSED_ENABLED_FOCUSED_SELECTED_WINDOW_FOCUSED_STATE_SET, PRESSED_ENABLED_FOCUSED_STATE_SET, PRESSED_ENABLED_FOCUSED_WINDOW_FOCUSED_STATE_SET, PRESSED_ENABLED_SELECTED_STATE_SET, PRESSED_ENABLED_SELECTED_WINDOW_FOCUSED_STATE_SET, PRESSED_ENABLED_STATE_SET, PRESSED_ENABLED_WINDOW_FOCUSED_STATE_SET, PRESSED_FOCUSED_SELECTED_STATE_SET, PRESSED_FOCUSED_SELECTED_WINDOW_FOCUSED_STATE_SET, PRESSED_FOCUSED_STATE_SET, PRESSED_FOCUSED_WINDOW_FOCUSED_STATE_SET, PRESSED_SELECTED_STATE_SET, PRESSED_SELECTED_WINDOW_FOCUSED_STATE_SET, PRESSED_STATE_SET, PRESSED_WINDOW_FOCUSED_STATE_SET, RIGHT, ROTATION, ROTATION_X, ROTATION_Y, SCALE_X, SCALE_Y, SCROLL_AXIS_HORIZONTAL, SCROLL_AXIS_NONE, SCROLL_AXIS_VERTICAL, SCROLL_INDICATOR_BOTTOM, SCROLL_INDICATOR_END, SCROLL_INDICATOR_LEFT, SCROLL_INDICATOR_RIGHT, SCROLL_INDICATOR_START, SCROLL_INDICATOR_TOP, SCROLL_X, SCROLL_Y, SCROLLBARS_INSIDE_INSET, SCROLLBARS_INSIDE_OVERLAY, SCROLLBARS_OUTSIDE_INSET, SCROLLBARS_OUTSIDE_OVERLAY, SELECTED_STATE_SET, SELECTED_WINDOW_FOCUSED_STATE_SET, SOUND_EFFECTS_ENABLED, TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_GRAVITY, TEXT_ALIGNMENT_INHERIT, TEXT_ALIGNMENT_TEXT_END, TEXT_ALIGNMENT_TEXT_START, TEXT_ALIGNMENT_VIEW_END, TEXT_ALIGNMENT_VIEW_START, TEXT_DIRECTION_ANY_RTL, TEXT_DIRECTION_FIRST_STRONG, TEXT_DIRECTION_FIRST_STRONG_LTR, TEXT_DIRECTION_FIRST_STRONG_RTL, TEXT_DIRECTION_INHERIT, TEXT_DIRECTION_LOCALE, TEXT_DIRECTION_LTR, TEXT_DIRECTION_RTL, TOP, TRANSLATION_X, TRANSLATION_Y, TRANSLATION_Z, TYPE_NON_TOUCH, TYPE_TOUCH, VIEW_MARKER, VISIBLE, WINDOW_FOCUSED_STATE_SET, X, Y, Z
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
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
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
boolean
protected void
protected void
dispatchDraw
(Canvas canvas) Draw the child views.boolean
dispatchKeyEvent
(KeyEvent event) Dispatch a key event to the next view on the focus path.protected <T extends View>
TfindViewByPredicateTraversal
(Predicate<View> predicate, View childToSkip) First look in our children, then in any header and footer views that may be scrolled off.protected <T extends View>
TfindViewTraversal
(int id) Returns the adapter currently in use in this ListView.Returns the drawable that will be drawn between each item in the list.int
int
int
boolean
int
protected void
Subclasses must override this method to layout their children.protected void
This is called when the view is detached from a window.protected void
onFocusChanged
(boolean gainFocus, int direction, Rect previouslyFocusedRect) Called by the view system when the focus state of this view changes.boolean
Default implementation: perform press of the view whenKeyEvent.KEY_ENTER
,KeyEvent.KEY_KP_ENTER
orKeyEvent.KEY_SPACE
is released, if the view is enabled and clickable.boolean
Default implementation: perform clicking of the view whenKeyEvent.KEY_ENTER
,KeyEvent.KEY_KP_ENTER
orKeyEvent.KEY_SPACE
is released.protected void
onMeasure
(int widthMeasureSpec, int heightMeasureSpec) Measure the view and its content to determine the measured width and the measured height.protected void
onSizeChanged
(int w, int h, int oldw, int oldh) Called when width or height changedprotected boolean
boolean
Removes a previously-added footer view.boolean
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
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
setSelection
(int position) Sets the currently selected item.void
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 void
protected HeaderViewListAdapter
wrapHeaderListAdapterInternal
(ArrayList<ListView.FixedViewInfo> headerViewInfos, ArrayList<ListView.FixedViewInfo> footerViewInfos, ListAdapter adapter) Methods inherited from class icyllis.modernui.widget.AbsListView
addTouchables, canScrollList, checkLayoutParams, clearChoices, computeVerticalScrollExtent, computeVerticalScrollOffset, computeVerticalScrollRange, dispatchDrawableHotspotChanged, dispatchSetPressed, drawableStateChanged, fling, generateDefaultLayoutParams, generateLayoutParams, getBottomEdgeEffectColor, getCheckedItemCount, getCheckedItemIds, getCheckedItemPosition, getCheckedItemPositions, getChoiceMode, getContextMenuInfo, getFocusedRect, getListPaddingBottom, getListPaddingLeft, getListPaddingRight, getListPaddingTop, getSelectedView, getSelector, getTopEdgeEffectColor, getTranscriptMode, handleDataChanged, internalSetPadding, invalidateViews, isDrawSelectorOnTop, isItemChecked, isSmoothScrollbarEnabled, isStackFromBottom, onAttachedToWindow, onCancelPendingInputEvents, onDrawForeground, onFilterComplete, onGenericMotionEvent, onInterceptTouchEvent, onLayout, onNestedFling, onNestedScroll, onNestedScrollAccepted, onOverScrolled, onStartNestedScroll, onTouchEvent, onTouchModeChanged, onWindowFocusChanged, performItemClick, pointToPosition, pointToRowId, reclaimViews, requestDisallowInterceptTouchEvent, requestLayout, scrollListBy, setBottomEdgeEffectColor, setChoiceMode, setDrawSelectorOnTop, setEdgeEffectColor, setFriction, setItemChecked, setMultiChoiceModeListener, setOnScrollListener, setRecyclerListener, setScrollIndicators, setSelectionFromTop, setSelector, setSmoothScrollbarEnabled, setStackFromBottom, setTopEdgeEffectColor, setTranscriptMode, setVelocityScale, shouldDrawSelector, showContextMenu, showContextMenuForChild, smoothScrollBy, smoothScrollToPosition, smoothScrollToPositionFromTop, smoothScrollToPositionFromTop, verifyDrawable
Methods inherited from class icyllis.modernui.widget.AdapterView
addView, addView, addView, addView, getCount, getEmptyView, getFirstVisiblePosition, getItemAtPosition, getItemIdAtPosition, getLastVisiblePosition, getOnItemClickListener, getOnItemLongClickListener, getOnItemSelectedListener, getPositionForView, getSelectedItem, getSelectedItemId, getSelectedItemPosition, removeAllViews, removeView, removeViewAt, setEmptyView, setFocusable, setFocusableInTouchMode, setOnClickListener, setOnItemClickListener, setOnItemLongClickListener, setOnItemSelectedListener
Methods inherited from class icyllis.modernui.view.ViewGroup
addFocusables, addKeyboardNavigationClusters, addStatesFromChildren, addTransientView, addView, addViewInLayout, addViewInLayout, attachViewToParent, bringChildToFront, childDrawableStateChanged, childHasTransientStateChanged, cleanupLayoutState, clearChildFocus, clearDisappearingChildren, clearFocus, detachAllViewsFromParent, detachViewFromParent, detachViewFromParent, detachViewsFromParent, dispatchFinishTemporaryDetach, dispatchGenericPointerEvent, dispatchHoverEvent, dispatchKeyShortcutEvent, dispatchSetActivated, dispatchSetSelected, dispatchStartTemporaryDetach, dispatchTouchEvent, dispatchVisibilityChanged, dispatchWindowFocusChanged, dispatchWindowVisibilityChanged, drawChild, endViewTransition, findFocus, focusableViewAvailable, focusSearch, getChildAt, getChildCount, getChildDrawingOrder, getChildDrawingOrder, getChildMeasureSpec, getChildVisibleRect, getChildVisibleRect, getClipChildren, getClipToPadding, getDescendantFocusability, getFocusedChild, getLayoutTransition, getNestedScrollAxes, getTouchscreenBlocksFocus, getTransientView, getTransientViewCount, getTransientViewIndex, hasBooleanFlag, hasFocus, hasTransientState, indexOfChild, isChildrenDrawingOrderEnabled, isLayoutSuppressed, isTransitionGroup, jumpDrawablesToCurrentState, layout, measureChild, measureChildren, measureChildWithMargins, offsetChildrenTopAndBottom, offsetDescendantRectToMyCoords, offsetRectIntoDescendantCoords, onChildVisibilityChanged, onCreateDrawableState, onInterceptHoverEvent, onNestedPreFling, onNestedPreScroll, onRequestFocusInDescendants, onResolvePointerIcon, onSetLayoutParams, onStopNestedScroll, onViewAdded, onViewRemoved, removeAllViewsInLayout, removeDetachedView, removeTransientView, removeViewInLayout, removeViews, removeViewsInLayout, requestChildFocus, requestFocus, requestTransitionStart, resetResolvedDrawables, resolveDrawables, resolveLayoutDirection, resolveLayoutParams, resolvePadding, resolveRtlPropertiesIfNeeded, resolveTextAlignment, resolveTextDirection, restoreDefaultFocus, setAddStatesFromChildren, setBooleanFlag, setChildrenDrawingOrderEnabled, setClipChildren, setClipToPadding, setDescendantFocusability, setLayoutTransition, setTouchscreenBlocksFocus, setTransitionGroup, shouldDelayChildPressedState, startActionModeForChild, startViewTransition, suppressLayout, transformPointToViewLocal, updateViewLayout
Methods inherited from class icyllis.modernui.view.View
addFocusables, addOnAttachStateChangeListener, addOnLayoutChangeListener, awakenScrollBars, awakenScrollBars, callOnClick, cancelLongPress, cancelPendingInputEvents, canReceivePointerEvents, canResolveLayoutDirection, canResolveTextAlignment, canResolveTextDirection, canScrollHorizontally, canScrollVertically, combineMeasuredStates, computeHorizontalScrollExtent, computeHorizontalScrollOffset, computeHorizontalScrollRange, computeScroll, createContextMenu, dispatchGenericMotionEvent, dispatchNestedFling, dispatchNestedPreFling, dispatchNestedPreScroll, dispatchNestedScroll, dispatchPointerEvent, dp, draw, drawableHotspotChanged, findViewById, findViewByPredicate, findViewByPredicateInsideOut, focusSearch, forceHasOverlappingRendering, forceLayout, generateViewId, getAlpha, getAnimationMatrix, getBackground, getBaseline, getBottom, getBoundsOnScreen, getBoundsOnScreen, getContext, getDefaultSize, getDrawableState, getDrawingRect, getElevation, getFadingEdge, getFadingEdgeLength, getFocusable, getFocusables, getForeground, getForegroundGravity, getGlobalVisibleRect, getGlobalVisibleRect, getHandler, getHasOverlappingRendering, getHeight, getHitRect, getHorizontalScrollbarHeight, getHorizontalScrollbarThumbDrawable, getHorizontalScrollbarTrackDrawable, getId, getInverseMatrix, getKeyDispatcherState, getLayoutDirection, getLayoutParams, getLeft, getLocalVisibleRect, getLocationInWindow, getLocationOnScreen, getMatrix, getMeasuredHeight, getMeasuredHeightAndState, getMeasuredState, getMeasuredWidth, getMeasuredWidthAndState, getMinimumHeight, getMinimumWidth, getNextClusterForwardId, getNextFocusDownId, getNextFocusForwardId, getNextFocusLeftId, getNextFocusRightId, getNextFocusUpId, getOnFocusChangeListener, getOnLongClickListener, getOverScrollMode, getPaddingBottom, getPaddingEnd, getPaddingLeft, getPaddingRight, getPaddingStart, getPaddingTop, getParent, getPivotX, getPivotY, getRawLayoutDirection, getRawTextAlignment, getRawTextDirection, getRevealOnFocusHint, getRight, getRootView, getRotation, getRotationX, getRotationY, getScaleX, getScaleY, getScrollBarDefaultDelayBeforeFade, getScrollBarFadeDuration, getScrollBarSize, getScrollBarStyle, getScrollIndicators, getScrollX, getScrollY, getStateListAnimator, getSuggestedMinimumHeight, getSuggestedMinimumWidth, getTag, getTextAlignment, getTextDirection, getTooltipText, getTooltipView, getTop, getTouchables, getTransitionAlpha, getTransitionName, getTranslationX, getTranslationY, getTranslationZ, getVerticalFadingEdgeLength, getVerticalScrollbarThumbDrawable, getVerticalScrollbarTrackDrawable, getVerticalScrollbarWidth, getViewRoot, getViewTreeObserver, getVisibility, getWidth, getWindowAttachCount, getWindowVisibility, getX, getY, getZ, hasExplicitFocusable, hasFocusable, hasIdentityMatrix, hasNestedScrollingParent, hasOnClickListeners, hasOnLongClickListeners, hasOverlappingRendering, hasTranslationTransientState, hasWindowFocus, invalidate, invalidateDrawable, isActivated, isAttachedToWindow, isClickable, isContextClickable, isDuplicateParentStateEnabled, isEnabled, isFocusable, isFocusableInTouchMode, isFocused, isFocusedByDefault, isForegroundInsidePadding, isHapticFeedbackEnabled, isHorizontalFadingEdgeEnabled, isHorizontalScrollBarEnabled, isHovered, isInLayout, isInScrollingContainer, isInTouchMode, isKeyboardNavigationCluster, isLaidOut, isLayoutDirectionInherited, isLayoutDirectionResolved, isLayoutRequested, isLayoutRtl, isLongClickable, isNestedScrollingEnabled, isPaddingRelative, isPivotSet, isPressed, isRootNamespace, isScrollbarFadingEnabled, isSelected, isShowingLayoutBounds, isShown, isSoundEffectsEnabled, isTemporarilyDetached, isTextAlignmentInherited, isTextAlignmentResolved, isTextDirectionInherited, isTextDirectionResolved, isVerticalFadingEdgeEnabled, isVerticalScrollBarEnabled, isVerticalScrollBarHidden, keyboardNavigationClusterSearch, mapRectFromViewToScreenCoords, measure, mergeDrawableStates, offsetLeftAndRight, offsetTopAndBottom, onCreateContextMenu, onDragEvent, onDraw, onDrawScrollBars, onFinishTemporaryDetach, onHoverChanged, onHoverEvent, onKeyShortcut, onResolveDrawables, onRtlPropertiesChanged, onScrollChanged, onStartTemporaryDetach, onVisibilityAggregated, onVisibilityChanged, onWindowVisibilityChanged, overScrollBy, performButtonActionOnTouchDown, performClick, performContextClick, performContextClick, performHapticFeedback, performHapticFeedback, performLongClick, performLongClick, playSoundEffect, pointInView, post, postDelayed, postInvalidate, postInvalidateDelayed, postInvalidateOnAnimation, postOnAnimation, postOnAnimationDelayed, refreshDrawableState, removeCallbacks, removeOnAttachStateChangeListener, removeOnLayoutChangeListener, requestFocus, requestFocus, requestRectangleOnScreen, requestRectangleOnScreen, requireViewById, resetPivot, resolveSize, resolveSizeAndState, scheduleDrawable, scrollBy, scrollTo, setActivated, setAlpha, setAnimationMatrix, setBackground, setBottom, setClickable, setContextClickable, setDuplicateParentStateEnabled, setElevation, setEnabled, setFocusable, setFocusedByDefault, setFocusedInCluster, setForeground, setForegroundGravity, setFrame, setHapticFeedbackEnabled, setHasTransientState, setHasTranslationTransientState, setHorizontalFadingEdgeEnabled, setHorizontalScrollBarEnabled, setHorizontalScrollbarThumbDrawable, setHorizontalScrollbarTrackDrawable, setHovered, setId, setIsRootNamespace, setKeyboardNavigationCluster, setLayoutDirection, setLayoutParams, setLeft, setLongClickable, setMeasuredDimension, setMinimumHeight, setMinimumWidth, setNestedScrollingEnabled, setNextClusterForwardId, setNextFocusDownId, setNextFocusForwardId, setNextFocusLeftId, setNextFocusRightId, setNextFocusUpId, setOnContextClickListener, setOnCreateContextMenuListener, setOnDragListener, setOnFocusChangeListener, setOnGenericMotionListener, setOnHoverListener, setOnKeyListener, setOnLongClickListener, setOnScrollChangeListener, setOnTouchListener, setOverScrollMode, setPadding, setPaddingRelative, setPivotX, setPivotY, setPressed, setRevealOnFocusHint, setRight, setRotation, setRotationX, setRotationY, setScaleX, setScaleY, setScrollBarDefaultDelayBeforeFade, setScrollBarFadeDuration, setScrollbarFadingEnabled, setScrollBarSize, setScrollBarStyle, setScrollIndicators, setScrollIndicators, setScrollX, setScrollY, setSelected, setSoundEffectsEnabled, setStateListAnimator, setTag, setTextAlignment, setTextDirection, setTooltipText, setTop, setTransitionAlpha, setTransitionName, setTransitionVisibility, setTranslationX, setTranslationY, setTranslationZ, setVerticalFadingEdgeEnabled, setVerticalScrollBarEnabled, setVerticalScrollbarThumbDrawable, setVerticalScrollbarTrackDrawable, setVisibility, setWillNotDraw, setX, setY, setZ, showContextMenu, sp, startActionMode, startActionMode, startDragAndDrop, startNestedScroll, stopNestedScroll, toGlobalMotionEvent, toLocalMotionEvent, toString, transformFromViewToWindowSpace, transformMatrixToGlobal, transformMatrixToLocal, unscheduleDrawable, unscheduleDrawable, willNotDraw
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface icyllis.modernui.view.ViewParent
canResolveLayoutDirection, canResolveTextAlignment, canResolveTextDirection, createContextMenu, getLayoutDirection, getParent, getTextAlignment, getTextDirection, isLayoutDirectionResolved, isLayoutRequested, isTextAlignmentResolved, isTextDirectionResolved, keyboardNavigationClusterSearch
-
Constructor Details
-
ListView
-
-
Method Details
-
getMaxScrollAmount
public int getMaxScrollAmount()- Returns:
- The maximum amount a list view will scroll in response to an arrow event.
-
addHeaderView
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.If the ListView's adapter does not extend
HeaderViewListAdapter
, it will be wrapped with a supporting instance ofWrapperListAdapter
.- Parameters:
v
- The view to add.data
- Data to associate with this viewisSelectable
- whether the item is selectable
-
addHeaderView
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.If the ListView's adapter does not extend
HeaderViewListAdapter
, it will be wrapped with a supporting instance ofWrapperListAdapter
.- Parameters:
v
- The view to add.
-
getHeaderViewsCount
public int getHeaderViewsCount() -
removeHeaderView
Removes a previously-added header view.- Parameters:
v
- The view to remove- Returns:
- true if the view was removed, false if the view was not a header view
-
getAdapter
Returns the adapter currently in use in this ListView. The returned adapter might not be the same adapter passed tosetAdapter(ListAdapter)
but might be aWrapperListAdapter
.- Specified by:
getAdapter
in classAdapterView<ListAdapter>
- Returns:
- The adapter currently used to display data in this ListView.
- See Also:
-
setAdapter
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.- Overrides:
setAdapter
in classAbsListView
- Parameters:
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.- See Also:
-
requestChildRectangleOnScreen
public boolean requestChildRectangleOnScreen(@NonNull View child, @NonNull Rect rect, boolean immediate) Description copied from interface:ViewParent
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
- Specified by:
requestChildRectangleOnScreen
in interfaceViewParent
- Overrides:
requestChildRectangleOnScreen
in classViewGroup
- Parameters:
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- Returns:
- Whether the group scrolled to handle the operation
-
smoothScrollToPosition
public void smoothScrollToPosition(int position) Smoothly scroll to the specified adapter position. The view will scroll such that the indicated position is displayed.- Overrides:
smoothScrollToPosition
in classAbsListView
- Parameters:
position
- Scroll to this adapter position.
-
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
- The amount to offset from the adapter position to scroll to.
-
onDetachedFromWindow
protected void onDetachedFromWindow()Description copied from class:View
This is called when the view is detached from a window. At this point it no longer has a surface for drawing.- Overrides:
onDetachedFromWindow
in classAbsListView
- See Also:
-
onSizeChanged
protected void onSizeChanged(int w, int h, int oldw, int oldh) Description copied from class:View
Called when width or height changed- Overrides:
onSizeChanged
in classAbsListView
- Parameters:
w
- new widthh
- new heightoldw
- previous widtholdh
- previous height
-
onMeasure
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) Description copied from class:View
Measure the view and its content to determine the measured width and the measured height. This method is invoked byView.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
View.setMeasuredDimension(int, int)
to store the measured width and height of this view. Failure to do so will trigger anIllegalStateException
, thrown byView.measure(int, int)
. Calling super.onMeasure() 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 the base one to provide better measurements of their content.
- Overrides:
onMeasure
in classAbsListView
- Parameters:
widthMeasureSpec
- width measure specification imposed by the parentMeasureSpec
heightMeasureSpec
- height measure specification imposed by the parentMeasureSpec
-
recycleOnMeasure
@Internal protected boolean recycleOnMeasure()- Returns:
- True to recycle the views used to measure this ListView in UNSPECIFIED/AT_MOST modes, false otherwise.
-
layoutChildren
protected void layoutChildren()Description copied from class:AbsListView
Subclasses must override this method to layout their children.- Overrides:
layoutChildren
in classAbsListView
-
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.- Specified by:
setSelection
in classAdapterView<ListAdapter>
- Parameters:
position
- 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. -
dispatchKeyEvent
Description copied from class:View
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.- Overrides:
dispatchKeyEvent
in classViewGroup
- Parameters:
event
- The key event to be dispatched.- Returns:
- True if the event was handled, false otherwise.
-
onKeyDown
Description copied from class:View
Default implementation: perform press of the view whenKeyEvent.KEY_ENTER
,KeyEvent.KEY_KP_ENTER
orKeyEvent.KEY_SPACE
is released, if the view is enabled and clickable.- Overrides:
onKeyDown
in classAbsListView
- Parameters:
keyCode
- a key code that represents the button pressed, fromKeyEvent
event
- the KeyEvent object that defines the button action
-
onKeyUp
Description copied from class:View
Default implementation: perform clicking of the view whenKeyEvent.KEY_ENTER
,KeyEvent.KEY_KP_ENTER
orKeyEvent.KEY_SPACE
is released.- Overrides:
onKeyUp
in classAbsListView
- Parameters:
keyCode
- A key code that represents the button pressed, fromKeyEvent
.event
- The KeyEvent object that defines the button action.
-
setItemsCanFocus
public void setItemsCanFocus(boolean itemsCanFocus) Indicates that the views created by the ListAdapter can contain focusable items.- Parameters:
itemsCanFocus
- true if items can get focus, false otherwise
-
getItemsCanFocus
public boolean getItemsCanFocus()- Returns:
- Whether the views created by the ListAdapter can contain focusable items.
-
dispatchDraw
Description copied from class:View
Draw the child views.- Overrides:
dispatchDraw
in classAbsListView
- Parameters:
canvas
- the canvas to draw content
-
getDivider
Returns the drawable that will be drawn between each item in the list.- Returns:
- the current drawable drawn between list elements
-
setDivider
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)
.- Parameters:
divider
- the drawable to use
-
getDividerHeight
public int getDividerHeight()- Returns:
- Returns the height of the divider that will be drawn between each item in the list.
-
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 bysetDivider(Drawable)
- Parameters:
height
- The new height of the divider in pixels.
-
setHeaderDividersEnabled
public void setHeaderDividersEnabled(boolean headerDividersEnabled) Enables or disables the drawing of the divider for header views.- Parameters:
headerDividersEnabled
- True to draw the headers, false otherwise.- See Also:
-
areHeaderDividersEnabled
public boolean areHeaderDividersEnabled()- Returns:
- Whether the drawing of the divider for header views is enabled
- See Also:
-
setOverscrollHeader
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
- The drawable to use
-
getOverscrollHeader
- Returns:
- The drawable that will be drawn above all other list content
-
onFocusChanged
protected void onFocusChanged(boolean gainFocus, int direction, @Nullable Rect previouslyFocusedRect) Description copied from class:View
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.- Overrides:
onFocusChanged
in classAbsListView
- Parameters:
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 areView.FOCUS_UP
,View.FOCUS_DOWN
,View.FOCUS_LEFT
,View.FOCUS_RIGHT
,View.FOCUS_FORWARD
, orView.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 benull
otherwise.
-
findViewTraversal
- Overrides:
findViewTraversal
in classViewGroup
- Parameters:
id
- the id of the view to be found- Returns:
- the view of the specified id, null if cannot be found
- See Also:
-
findViewByPredicateTraversal
protected <T extends View> T findViewByPredicateTraversal(@NonNull Predicate<View> predicate, View childToSkip) First look in our children, then in any header and footer views that may be scrolled off.- Overrides:
findViewByPredicateTraversal
in classViewGroup
- Parameters:
predicate
- The predicate to evaluate.childToSkip
- If not null, ignores this child during the recursive traversal.- Returns:
- The first view that matches the predicate or null.
- See Also:
-
wrapHeaderListAdapterInternal
@Internal @NonNull protected HeaderViewListAdapter wrapHeaderListAdapterInternal(ArrayList<ListView.FixedViewInfo> headerViewInfos, ArrayList<ListView.FixedViewInfo> footerViewInfos, ListAdapter adapter) -
wrapHeaderListAdapterInternal
@Internal protected void wrapHeaderListAdapterInternal() -
dispatchDataSetObserverOnChangedInternal
@Internal protected void dispatchDataSetObserverOnChangedInternal()
-