Show
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 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 In order to display items in the list, call To display a more custom view for each item in your dataset, implement a ListAdapter. For example, extend 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 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 Summary
XML attributesandroid:dividerDrawable or color to draw between list items. May be a reference to another resource, in the form " May be a color value, in the form of " Related methods:
android:dividerHeightHeight 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 " android:entriesReference 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 " android:footerDividersEnabledWhen 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 " android:headerDividersEnabledWhen 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 " Public constructorsListViewAdded in API level 1 public ListView (Context context)
ListViewAdded in API level 1 public ListView (Context context, AttributeSet attrs)
ListViewAdded in API level 1 public ListView (Context context, AttributeSet attrs, int defStyleAttr)
ListViewAdded in API level 21 public ListView (Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes)
Public methodsaddFooterViewAdded in API level 1 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
addFooterViewAdded in API level 1 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
addHeaderViewAdded in API level 1 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
addHeaderViewAdded in API level 1 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
areFooterDividersEnabledAdded in API level 19 public boolean areFooterDividersEnabled ()
See also:
areHeaderDividersEnabledAdded in API level 19 public boolean areHeaderDividersEnabled ()
See also:
dispatchKeyEventAdded in API level 1 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.
getAccessibilityClassNameAdded in API level 23 public CharSequence getAccessibilityClassName () A TYPE_VIEW_SCROLLED event should be sent whenever a scroll happens, even if the mFirstPosition and the child count have not changed.
getAdapterAdded in API level 1 public ListAdapter getAdapter () Returns the adapter currently in use in this ListView. The returned adapter might not be the same adapter passed to
See also:
getCheckItemIds Added in API level 4 public long[] getCheckItemIds () This method was deprecated in API level 15. Returns the set of checked items ids. The result is only valid if the choice mode has not been set to
getDividerAdded in API level 1 public Drawable getDivider () Returns the drawable that will be drawn between each item in the list. Related XML Attributes:
getDividerHeightAdded in API level 1 public int getDividerHeight ()
getFooterViewsCountAdded in API level 1 public int getFooterViewsCount ()
getHeaderViewsCountAdded in API level 1 public int getHeaderViewsCount ()
getItemsCanFocusAdded in API level 1 public boolean getItemsCanFocus ()
getMaxScrollAmountAdded in API level 1 public int getMaxScrollAmount ()
getOverscrollFooterAdded in API level 9 public Drawable getOverscrollFooter ()
getOverscrollHeaderAdded in API level 9 public Drawable getOverscrollHeader ()
isOpaqueAdded in API level 7 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.
onInitializeAccessibilityNodeInfoForItemAdded in API level 19 public void onInitializeAccessibilityNodeInfoForItem (View view, int position, AccessibilityNodeInfo info) Initializes an
onKeyDownAdded in API level 1 public boolean onKeyDown (int keyCode, KeyEvent event) Default implementation of 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.
onKeyMultipleAdded in API level 1 public boolean onKeyMultiple (int keyCode, int repeatCount, KeyEvent event) Default implementation of 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.
onKeyUpAdded in API level 1 public boolean onKeyUp (int keyCode, KeyEvent event) Default implementation of 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.
removeFooterViewAdded in API level 1 public boolean removeFooterView (View v) Removes a previously-added footer view.
removeHeaderViewAdded in API level 1 public boolean removeHeaderView (View v) Removes a previously-added header view.
requestChildRectangleOnScreenAdded in API level 1 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.
setAdapterAdded in API level 1 public void setAdapter (ListAdapter adapter) Sets the data behind this ListView. The adapter passed to this method may be wrapped by a
See also:
setCacheColorHintAdded in API level 1 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
setDividerAdded in API level 1 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 Related XML Attributes:
setDividerHeightAdded in API level 1 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
setFooterDividersEnabledAdded in API level 3 public void setFooterDividersEnabled (boolean footerDividersEnabled) Enables or disables the drawing of the divider for footer views.
See also:
setHeaderDividersEnabledAdded in API level 3 public void setHeaderDividersEnabled (boolean headerDividersEnabled) Enables or disables the drawing of the divider for header views.
See also:
setItemsCanFocusAdded in API level 1 public void setItemsCanFocus (boolean itemsCanFocus) Indicates that the views created by the ListAdapter can contain focusable items.
setOverscrollFooterAdded in API level 9 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.
setOverscrollHeaderAdded in API level 9 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.
setRemoteViewsAdapterAdded in API level 11 public void setRemoteViewsAdapter (Intent intent) Sets up this AbsListView to use a remote views adapter which connects to a RemoteViewsService through the specified intent.
setSelectionAdded in API level 1 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.
setSelectionAfterHeaderViewAdded in API level 1 public void setSelectionAfterHeaderView () setSelectionAfterHeaderView set the selection to be the first list item after the header views. smoothScrollByOffsetAdded in API level 11 public void smoothScrollByOffset (int offset) Smoothly scroll to the specified adapter position offset. The view will scroll such that the indicated position is displayed.
smoothScrollToPositionAdded in API level 8 public void smoothScrollToPosition (int position) Smoothly scroll to the specified adapter position. The view will scroll such that the indicated position is displayed.
Protected methodscanAnimateAdded in API level 1 protected boolean canAnimate () Indicates whether the view group has the ability to animate its children after the first layout.
dispatchDrawAdded in API level 1 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).
drawChildAdded in API level 1 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.
layoutChildrenAdded in API level 1 protected void layoutChildren () Subclasses must override this method to layout their children. onDetachedFromWindowAdded in API level 1 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. onFinishInflateAdded in API level 1 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. onFocusChangedAdded in API level 1 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.
onMeasureAdded in API level 1 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 CONTRACT: When overriding this method, you must call The base class implementation of measure defaults to the background size, unless a larger size is allowed by the MeasureSpec. Subclasses should override 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 (
onSizeChangedAdded in API level 1 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.
Content and code samples on this page are subject to the licenses described in the Content License. Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates. Last updated 2022-06-08 UTC. [{ "type": "thumb-down", "id": "missingTheInformationINeed", "label":"Missing the information I need" },{ "type": "thumb-down", "id": "tooComplicatedTooManySteps", "label":"Too complicated / too many steps" },{ "type": "thumb-down", "id": "outOfDate", "label":"Out of date" },{ "type": "thumb-down", "id": "samplesCodeIssue", "label":"Samples / code issue" },{ "type": "thumb-down", "id": "otherDown", "label":"Other" }] [{ "type": "thumb-up", "id": "easyToUnderstand", "label":"Easy to understand" },{ "type": "thumb-up", "id": "solvedMyProblem", "label":"Solved my problem" },{ "type": "thumb-up", "id": "otherUp", "label":"Other" }] What is the recommended maximum number of lines of text when constructing slides for presentation?Don't make your audience read the slides either. Keep text to a minimum (6-8 lines per slide, no more than 30 words per slide). The bullet points should be headlines, not news articles. Write in sentence fragments using key words, and keep your font size 24 or bigger.
What allows you to enter text anywhere on a slide without using a placeholder?Use text boxes to place text anywhere on a slide, such as outside a text placeholder. For example, to add a caption to a picture, create a text box and position it near the picture.
What should all presentations have?All types of presentations consist of three basic parts: the introduction, the body, and the conclusion. In general, the introduction should be about 10-15% of your speaking time, the body around 75%, and the conclusion only 10%.
Which of the following views should you use if you want to recognize slides and apply transition effects?Introduction to Computers
Which of the following views should you use if you want to reorganize slides and apply transition effects? Option 3. Slide Sorter is the correct answer.
|