diff --git a/core/java/android/widget/ListView.java b/core/java/android/widget/ListView.java index 12e35a14e3814..569fe017ac860 100644 --- a/core/java/android/widget/ListView.java +++ b/core/java/android/widget/ListView.java @@ -67,11 +67,77 @@ import java.util.function.Predicate; /** - * A view that shows items in a vertically scrolling list. The items - * come from the {@link ListAdapter} associated with this view. + *
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 {@link android.support.v7.widget.RecyclerView}.
* - *See the List View - * guide.
+ *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 {@link 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 {@link #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 {@link BaseAdapter} and create and configure the view for each data item in + * {@code 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 + * {@code convertView} provided to {@code 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 {@link android.app.ListActivity ListActivity} + * or {@link android.app.ListFragment 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.
* * @attr ref android.R.styleable#ListView_entries * @attr ref android.R.styleable#ListView_divider