15ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn/* 25ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn * Copyright (C) 2010 The Android Open Source Project 35ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn * 45ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn * Licensed under the Apache License, Version 2.0 (the "License"); 55ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn * you may not use this file except in compliance with the License. 65ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn * You may obtain a copy of the License at 75ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn * 85ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn * http://www.apache.org/licenses/LICENSE-2.0 95ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn * 105ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn * Unless required by applicable law or agreed to in writing, software 115ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn * distributed under the License is distributed on an "AS IS" BASIS, 125ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 135ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn * See the License for the specific language governing permissions and 145ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn * limitations under the License. 155ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn */ 165ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn 175ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackbornpackage android.app; 185ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn 195ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackbornimport android.os.Bundle; 205ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackbornimport android.os.Handler; 215ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackbornimport android.view.LayoutInflater; 225ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackbornimport android.view.View; 235ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackbornimport android.view.ViewGroup; 24445646c52128a763b56ed7bb3bd009e2f33e3e4fDianne Hackbornimport android.view.animation.AnimationUtils; 255ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackbornimport android.widget.AdapterView; 265ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackbornimport android.widget.ListAdapter; 275ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackbornimport android.widget.ListView; 28445646c52128a763b56ed7bb3bd009e2f33e3e4fDianne Hackbornimport android.widget.TextView; 295ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn 305ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn/** 31dd913a50cd72d6dd23c4ea437f0ebe2be05ca2e8Dianne Hackborn * A fragment that displays a list of items by binding to a data source such as 325ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn * an array or Cursor, and exposes event handlers when the user selects an item. 335ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn * <p> 34dd913a50cd72d6dd23c4ea437f0ebe2be05ca2e8Dianne Hackborn * ListFragment hosts a {@link android.widget.ListView ListView} object that can 355ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn * be bound to different data sources, typically either an array or a Cursor 365ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn * holding query results. Binding, screen layout, and row layout are discussed 375ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn * in the following sections. 385ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn * <p> 395ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn * <strong>Screen Layout</strong> 405ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn * </p> 415ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn * <p> 42dd913a50cd72d6dd23c4ea437f0ebe2be05ca2e8Dianne Hackborn * ListFragment has a default layout that consists of a single list view. 435ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn * However, if you desire, you can customize the fragment layout by returning 445ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn * your own view hierarchy from {@link #onCreateView}. 45dd913a50cd72d6dd23c4ea437f0ebe2be05ca2e8Dianne Hackborn * To do this, your view hierarchy <em>must</em> contain a ListView object with the 465ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn * id "@android:id/list" (or {@link android.R.id#list} if it's in code) 475ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn * <p> 485ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn * Optionally, your view hierarchy can contain another view object of any type to 495ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn * display when the list view is empty. This "empty list" notifier must have an 505ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn * id "android:empty". Note that when an empty view is present, the list view 515ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn * will be hidden when there is no data to display. 525ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn * <p> 53dd913a50cd72d6dd23c4ea437f0ebe2be05ca2e8Dianne Hackborn * The following code demonstrates an (ugly) custom list layout. It has a list 545ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn * with a green background, and an alternate red "no data" message. 555ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn * </p> 565ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn * 575ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn * <pre> 585ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn * <?xml version="1.0" encoding="utf-8"?> 595ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn * <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 605ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn * android:orientation="vertical" 615ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn * android:layout_width="match_parent" 625ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn * android:layout_height="match_parent" 635ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn * android:paddingLeft="8dp" 645ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn * android:paddingRight="8dp"> 655ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn * 665ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn * <ListView android:id="@id/android:list" 675ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn * android:layout_width="match_parent" 685ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn * android:layout_height="match_parent" 695ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn * android:background="#00FF00" 705ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn * android:layout_weight="1" 715ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn * android:drawSelectorOnTop="false"/> 725ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn * 735ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn * <TextView android:id="@id/android:empty" 745ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn * android:layout_width="match_parent" 755ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn * android:layout_height="match_parent" 765ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn * android:background="#FF0000" 775ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn * android:text="No data"/> 785ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn * </LinearLayout> 795ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn * </pre> 805ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn * 815ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn * <p> 825ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn * <strong>Row Layout</strong> 835ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn * </p> 845ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn * <p> 855ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn * You can specify the layout of individual rows in the list. You do this by 865ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn * specifying a layout resource in the ListAdapter object hosted by the fragment 875ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn * (the ListAdapter binds the ListView to the data; more on this later). 885ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn * <p> 895ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn * A ListAdapter constructor takes a parameter that specifies a layout resource 905ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn * for each row. It also has two additional parameters that let you specify 915ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn * which data field to associate with which object in the row layout resource. 925ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn * These two parameters are typically parallel arrays. 935ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn * </p> 945ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn * <p> 955ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn * Android provides some standard row layout resources. These are in the 965ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn * {@link android.R.layout} class, and have names such as simple_list_item_1, 975ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn * simple_list_item_2, and two_line_list_item. The following layout XML is the 985ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn * source for the resource two_line_list_item, which displays two data 995ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn * fields,one above the other, for each list row. 1005ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn * </p> 1015ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn * 1025ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn * <pre> 1035ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn * <?xml version="1.0" encoding="utf-8"?> 1045ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn * <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 1055ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn * android:layout_width="match_parent" 1065ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn * android:layout_height="wrap_content" 1075ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn * android:orientation="vertical"> 1085ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn * 1095ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn * <TextView android:id="@+id/text1" 1105ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn * android:textSize="16sp" 1115ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn * android:textStyle="bold" 1125ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn * android:layout_width="match_parent" 1135ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn * android:layout_height="wrap_content"/> 1145ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn * 1155ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn * <TextView android:id="@+id/text2" 1165ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn * android:textSize="16sp" 1175ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn * android:layout_width="match_parent" 1185ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn * android:layout_height="wrap_content"/> 1195ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn * </LinearLayout> 1205ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn * </pre> 1215ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn * 1225ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn * <p> 1235ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn * You must identify the data bound to each TextView object in this layout. The 1245ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn * syntax for this is discussed in the next section. 1255ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn * </p> 1265ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn * <p> 1275ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn * <strong>Binding to Data</strong> 1285ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn * </p> 1295ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn * <p> 1305ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn * You bind the ListFragment's ListView object to data using a class that 1315ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn * implements the {@link android.widget.ListAdapter ListAdapter} interface. 1325ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn * Android provides two standard list adapters: 1335ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn * {@link android.widget.SimpleAdapter SimpleAdapter} for static data (Maps), 1345ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn * and {@link android.widget.SimpleCursorAdapter SimpleCursorAdapter} for Cursor 1355ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn * query results. 1365ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn * </p> 137dd913a50cd72d6dd23c4ea437f0ebe2be05ca2e8Dianne Hackborn * <p> 138dd913a50cd72d6dd23c4ea437f0ebe2be05ca2e8Dianne Hackborn * You <b>must</b> use 139dd913a50cd72d6dd23c4ea437f0ebe2be05ca2e8Dianne Hackborn * {@link #setListAdapter(ListAdapter) ListFragment.setListAdapter()} to 140dd913a50cd72d6dd23c4ea437f0ebe2be05ca2e8Dianne Hackborn * associate the list with an adapter. Do not directly call 141dd913a50cd72d6dd23c4ea437f0ebe2be05ca2e8Dianne Hackborn * {@link ListView#setAdapter(ListAdapter) ListView.setAdapter()} or else 142dd913a50cd72d6dd23c4ea437f0ebe2be05ca2e8Dianne Hackborn * important initialization will be skipped. 143dd913a50cd72d6dd23c4ea437f0ebe2be05ca2e8Dianne Hackborn * </p> 1445ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn * 1455ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn * @see #setListAdapter 1465ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn * @see android.widget.ListView 1475ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn */ 1485ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackbornpublic class ListFragment extends Fragment { 1495ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn final private Handler mHandler = new Handler(); 1505ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn 1515ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn final private Runnable mRequestFocus = new Runnable() { 1525ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn public void run() { 1535ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn mList.focusableViewAvailable(mList); 1545ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn } 1555ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn }; 1565ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn 1575ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn final private AdapterView.OnItemClickListener mOnClickListener 1585ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn = new AdapterView.OnItemClickListener() { 1595ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn public void onItemClick(AdapterView<?> parent, View v, int position, long id) { 1605ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn onListItemClick((ListView)parent, v, position, id); 1615ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn } 1625ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn }; 1635ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn 1645ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn ListAdapter mAdapter; 1655ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn ListView mList; 166445646c52128a763b56ed7bb3bd009e2f33e3e4fDianne Hackborn View mEmptyView; 167445646c52128a763b56ed7bb3bd009e2f33e3e4fDianne Hackborn TextView mStandardEmptyView; 168445646c52128a763b56ed7bb3bd009e2f33e3e4fDianne Hackborn View mProgressContainer; 169445646c52128a763b56ed7bb3bd009e2f33e3e4fDianne Hackborn View mListContainer; 170afc4b283fdaedec9bf32492a019b43cc33edc9b6Dianne Hackborn CharSequence mEmptyText; 171445646c52128a763b56ed7bb3bd009e2f33e3e4fDianne Hackborn boolean mListShown; 1725ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn 1735ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn public ListFragment() { 1745ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn } 1755ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn 1765ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn /** 177445646c52128a763b56ed7bb3bd009e2f33e3e4fDianne Hackborn * Provide default implementation to return a simple list view. Subclasses 178445646c52128a763b56ed7bb3bd009e2f33e3e4fDianne Hackborn * can override to replace with their own layout. If doing so, the 179445646c52128a763b56ed7bb3bd009e2f33e3e4fDianne Hackborn * returned view hierarchy <em>must</em> have a ListView whose id 180b0c56b24aada23461c04746926ba185dfdbb8b5bDianne Hackborn * is {@link android.R.id#list android.R.id.list} and can optionally 181b0c56b24aada23461c04746926ba185dfdbb8b5bDianne Hackborn * have a sibling view id {@link android.R.id#empty android.R.id.empty} 182445646c52128a763b56ed7bb3bd009e2f33e3e4fDianne Hackborn * that is to be shown when the list is empty. 183ef769f6e4849d5d2580570ce08f9493dd43e7f0dDianne Hackborn * 184ef769f6e4849d5d2580570ce08f9493dd43e7f0dDianne Hackborn * <p>If you are overriding this method with your own custom content, 185ef769f6e4849d5d2580570ce08f9493dd43e7f0dDianne Hackborn * consider including the standard layout {@link android.R.layout#list_content} 186ef769f6e4849d5d2580570ce08f9493dd43e7f0dDianne Hackborn * in your layout file, so that you continue to retain all of the standard 187ef769f6e4849d5d2580570ce08f9493dd43e7f0dDianne Hackborn * behavior of ListFragment. In particular, this is currently the only 188ef769f6e4849d5d2580570ce08f9493dd43e7f0dDianne Hackborn * way to have the built-in indeterminant progress state be shown. 1895ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn */ 1905ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn @Override 1915ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn public View onCreateView(LayoutInflater inflater, ViewGroup container, 1925ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn Bundle savedInstanceState) { 193ef769f6e4849d5d2580570ce08f9493dd43e7f0dDianne Hackborn return inflater.inflate(com.android.internal.R.layout.list_content, 1945ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn container, false); 1955ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn } 1965ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn 1975ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn /** 19816f6e89c2a4bbf73fe15cb2e81c8fec98c7ac831Dianne Hackborn * Attach to list view once the view hierarchy has been created. 1995ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn */ 2005ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn @Override 20116f6e89c2a4bbf73fe15cb2e81c8fec98c7ac831Dianne Hackborn public void onViewCreated(View view, Bundle savedInstanceState) { 20216f6e89c2a4bbf73fe15cb2e81c8fec98c7ac831Dianne Hackborn super.onViewCreated(view, savedInstanceState); 2035ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn ensureList(); 2045ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn } 2055ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn 2065ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn /** 2075ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn * Detach from list view. 2085ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn */ 2095ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn @Override 2105ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn public void onDestroyView() { 2115ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn mHandler.removeCallbacks(mRequestFocus); 2125ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn mList = null; 213afc4b283fdaedec9bf32492a019b43cc33edc9b6Dianne Hackborn mListShown = false; 214afc4b283fdaedec9bf32492a019b43cc33edc9b6Dianne Hackborn mEmptyView = mProgressContainer = mListContainer = null; 215afc4b283fdaedec9bf32492a019b43cc33edc9b6Dianne Hackborn mStandardEmptyView = null; 2165ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn super.onDestroyView(); 2175ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn } 2185ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn 2195ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn /** 2205ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn * This method will be called when an item in the list is selected. 2215ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn * Subclasses should override. Subclasses can call 2225ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn * getListView().getItemAtPosition(position) if they need to access the 2235ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn * data associated with the selected item. 2245ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn * 2255ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn * @param l The ListView where the click happened 2265ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn * @param v The view that was clicked within the ListView 2275ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn * @param position The position of the view in the list 2285ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn * @param id The row id of the item that was clicked 2295ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn */ 2305ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn public void onListItemClick(ListView l, View v, int position, long id) { 2315ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn } 2325ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn 2335ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn /** 2345ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn * Provide the cursor for the list view. 2355ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn */ 2365ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn public void setListAdapter(ListAdapter adapter) { 237ef769f6e4849d5d2580570ce08f9493dd43e7f0dDianne Hackborn boolean hadAdapter = mAdapter != null; 2385ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn mAdapter = adapter; 2395ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn if (mList != null) { 2405ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn mList.setAdapter(adapter); 241ef769f6e4849d5d2580570ce08f9493dd43e7f0dDianne Hackborn if (!mListShown && !hadAdapter) { 242ef769f6e4849d5d2580570ce08f9493dd43e7f0dDianne Hackborn // The list was hidden, and previously didn't have an 243ef769f6e4849d5d2580570ce08f9493dd43e7f0dDianne Hackborn // adapter. It is now time to show it. 244ef769f6e4849d5d2580570ce08f9493dd43e7f0dDianne Hackborn setListShown(true, getView().getWindowToken() != null); 245ef769f6e4849d5d2580570ce08f9493dd43e7f0dDianne Hackborn } 2465ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn } 2475ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn } 2485ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn 2495ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn /** 2505ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn * Set the currently selected list item to the specified 2515ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn * position with the adapter's data 2525ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn * 2535ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn * @param position 2545ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn */ 2555ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn public void setSelection(int position) { 2565ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn ensureList(); 2575ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn mList.setSelection(position); 2585ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn } 2595ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn 2605ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn /** 2615ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn * Get the position of the currently selected list item. 2625ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn */ 2635ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn public int getSelectedItemPosition() { 2645ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn ensureList(); 2655ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn return mList.getSelectedItemPosition(); 2665ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn } 2675ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn 2685ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn /** 2695ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn * Get the cursor row ID of the currently selected list item. 2705ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn */ 2715ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn public long getSelectedItemId() { 2725ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn ensureList(); 2735ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn return mList.getSelectedItemId(); 2745ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn } 2755ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn 2765ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn /** 2775ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn * Get the activity's list view widget. 2785ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn */ 2795ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn public ListView getListView() { 2805ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn ensureList(); 2815ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn return mList; 2825ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn } 2835ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn 2845ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn /** 285445646c52128a763b56ed7bb3bd009e2f33e3e4fDianne Hackborn * The default content for a ListFragment has a TextView that can 286445646c52128a763b56ed7bb3bd009e2f33e3e4fDianne Hackborn * be shown when the list is empty. If you would like to have it 287445646c52128a763b56ed7bb3bd009e2f33e3e4fDianne Hackborn * shown, call this method to supply the text it should use. 288445646c52128a763b56ed7bb3bd009e2f33e3e4fDianne Hackborn */ 289445646c52128a763b56ed7bb3bd009e2f33e3e4fDianne Hackborn public void setEmptyText(CharSequence text) { 290445646c52128a763b56ed7bb3bd009e2f33e3e4fDianne Hackborn ensureList(); 291445646c52128a763b56ed7bb3bd009e2f33e3e4fDianne Hackborn if (mStandardEmptyView == null) { 292445646c52128a763b56ed7bb3bd009e2f33e3e4fDianne Hackborn throw new IllegalStateException("Can't be used with a custom content view"); 293445646c52128a763b56ed7bb3bd009e2f33e3e4fDianne Hackborn } 294dd913a50cd72d6dd23c4ea437f0ebe2be05ca2e8Dianne Hackborn mStandardEmptyView.setText(text); 295afc4b283fdaedec9bf32492a019b43cc33edc9b6Dianne Hackborn if (mEmptyText == null) { 296dd913a50cd72d6dd23c4ea437f0ebe2be05ca2e8Dianne Hackborn mList.setEmptyView(mStandardEmptyView); 297dd913a50cd72d6dd23c4ea437f0ebe2be05ca2e8Dianne Hackborn } 298afc4b283fdaedec9bf32492a019b43cc33edc9b6Dianne Hackborn mEmptyText = text; 299445646c52128a763b56ed7bb3bd009e2f33e3e4fDianne Hackborn } 300445646c52128a763b56ed7bb3bd009e2f33e3e4fDianne Hackborn 301445646c52128a763b56ed7bb3bd009e2f33e3e4fDianne Hackborn /** 302445646c52128a763b56ed7bb3bd009e2f33e3e4fDianne Hackborn * Control whether the list is being displayed. You can make it not 303445646c52128a763b56ed7bb3bd009e2f33e3e4fDianne Hackborn * displayed if you are waiting for the initial data to show in it. During 304445646c52128a763b56ed7bb3bd009e2f33e3e4fDianne Hackborn * this time an indeterminant progress indicator will be shown instead. 305445646c52128a763b56ed7bb3bd009e2f33e3e4fDianne Hackborn * 306ef769f6e4849d5d2580570ce08f9493dd43e7f0dDianne Hackborn * <p>Applications do not normally need to use this themselves. The default 307ef769f6e4849d5d2580570ce08f9493dd43e7f0dDianne Hackborn * behavior of ListFragment is to start with the list not being shown, only 308ef769f6e4849d5d2580570ce08f9493dd43e7f0dDianne Hackborn * showing it once an adapter is given with {@link #setListAdapter(ListAdapter)}. 309ef769f6e4849d5d2580570ce08f9493dd43e7f0dDianne Hackborn * If the list at that point had not been shown, when it does get shown 310ef769f6e4849d5d2580570ce08f9493dd43e7f0dDianne Hackborn * it will be do without the user ever seeing the hidden state. 311ef769f6e4849d5d2580570ce08f9493dd43e7f0dDianne Hackborn * 312ef769f6e4849d5d2580570ce08f9493dd43e7f0dDianne Hackborn * @param shown If true, the list view is shown; if false, the progress 313ef769f6e4849d5d2580570ce08f9493dd43e7f0dDianne Hackborn * indicator. The initial value is true. 314ef769f6e4849d5d2580570ce08f9493dd43e7f0dDianne Hackborn */ 315ef769f6e4849d5d2580570ce08f9493dd43e7f0dDianne Hackborn public void setListShown(boolean shown) { 316ef769f6e4849d5d2580570ce08f9493dd43e7f0dDianne Hackborn setListShown(shown, true); 317ef769f6e4849d5d2580570ce08f9493dd43e7f0dDianne Hackborn } 318ef769f6e4849d5d2580570ce08f9493dd43e7f0dDianne Hackborn 319ef769f6e4849d5d2580570ce08f9493dd43e7f0dDianne Hackborn /** 320ef769f6e4849d5d2580570ce08f9493dd43e7f0dDianne Hackborn * Like {@link #setListShown(boolean)}, but no animation is used when 321ef769f6e4849d5d2580570ce08f9493dd43e7f0dDianne Hackborn * transitioning from the previous state. 322ef769f6e4849d5d2580570ce08f9493dd43e7f0dDianne Hackborn */ 323ef769f6e4849d5d2580570ce08f9493dd43e7f0dDianne Hackborn public void setListShownNoAnimation(boolean shown) { 324ef769f6e4849d5d2580570ce08f9493dd43e7f0dDianne Hackborn setListShown(shown, false); 325ef769f6e4849d5d2580570ce08f9493dd43e7f0dDianne Hackborn } 326ef769f6e4849d5d2580570ce08f9493dd43e7f0dDianne Hackborn 327ef769f6e4849d5d2580570ce08f9493dd43e7f0dDianne Hackborn /** 328ef769f6e4849d5d2580570ce08f9493dd43e7f0dDianne Hackborn * Control whether the list is being displayed. You can make it not 329ef769f6e4849d5d2580570ce08f9493dd43e7f0dDianne Hackborn * displayed if you are waiting for the initial data to show in it. During 330ef769f6e4849d5d2580570ce08f9493dd43e7f0dDianne Hackborn * this time an indeterminant progress indicator will be shown instead. 331ef769f6e4849d5d2580570ce08f9493dd43e7f0dDianne Hackborn * 332445646c52128a763b56ed7bb3bd009e2f33e3e4fDianne Hackborn * @param shown If true, the list view is shown; if false, the progress 333445646c52128a763b56ed7bb3bd009e2f33e3e4fDianne Hackborn * indicator. The initial value is true. 334445646c52128a763b56ed7bb3bd009e2f33e3e4fDianne Hackborn * @param animate If true, an animation will be used to transition to the 335445646c52128a763b56ed7bb3bd009e2f33e3e4fDianne Hackborn * new state. 336445646c52128a763b56ed7bb3bd009e2f33e3e4fDianne Hackborn */ 337ef769f6e4849d5d2580570ce08f9493dd43e7f0dDianne Hackborn private void setListShown(boolean shown, boolean animate) { 338445646c52128a763b56ed7bb3bd009e2f33e3e4fDianne Hackborn ensureList(); 339445646c52128a763b56ed7bb3bd009e2f33e3e4fDianne Hackborn if (mProgressContainer == null) { 340445646c52128a763b56ed7bb3bd009e2f33e3e4fDianne Hackborn throw new IllegalStateException("Can't be used with a custom content view"); 341445646c52128a763b56ed7bb3bd009e2f33e3e4fDianne Hackborn } 342445646c52128a763b56ed7bb3bd009e2f33e3e4fDianne Hackborn if (mListShown == shown) { 343445646c52128a763b56ed7bb3bd009e2f33e3e4fDianne Hackborn return; 344445646c52128a763b56ed7bb3bd009e2f33e3e4fDianne Hackborn } 345445646c52128a763b56ed7bb3bd009e2f33e3e4fDianne Hackborn mListShown = shown; 346445646c52128a763b56ed7bb3bd009e2f33e3e4fDianne Hackborn if (shown) { 347445646c52128a763b56ed7bb3bd009e2f33e3e4fDianne Hackborn if (animate) { 348445646c52128a763b56ed7bb3bd009e2f33e3e4fDianne Hackborn mProgressContainer.startAnimation(AnimationUtils.loadAnimation( 349445646c52128a763b56ed7bb3bd009e2f33e3e4fDianne Hackborn getActivity(), android.R.anim.fade_out)); 350445646c52128a763b56ed7bb3bd009e2f33e3e4fDianne Hackborn mListContainer.startAnimation(AnimationUtils.loadAnimation( 351445646c52128a763b56ed7bb3bd009e2f33e3e4fDianne Hackborn getActivity(), android.R.anim.fade_in)); 352afc4b283fdaedec9bf32492a019b43cc33edc9b6Dianne Hackborn } else { 353afc4b283fdaedec9bf32492a019b43cc33edc9b6Dianne Hackborn mProgressContainer.clearAnimation(); 354afc4b283fdaedec9bf32492a019b43cc33edc9b6Dianne Hackborn mListContainer.clearAnimation(); 355445646c52128a763b56ed7bb3bd009e2f33e3e4fDianne Hackborn } 356445646c52128a763b56ed7bb3bd009e2f33e3e4fDianne Hackborn mProgressContainer.setVisibility(View.GONE); 357445646c52128a763b56ed7bb3bd009e2f33e3e4fDianne Hackborn mListContainer.setVisibility(View.VISIBLE); 358445646c52128a763b56ed7bb3bd009e2f33e3e4fDianne Hackborn } else { 359445646c52128a763b56ed7bb3bd009e2f33e3e4fDianne Hackborn if (animate) { 360445646c52128a763b56ed7bb3bd009e2f33e3e4fDianne Hackborn mProgressContainer.startAnimation(AnimationUtils.loadAnimation( 361445646c52128a763b56ed7bb3bd009e2f33e3e4fDianne Hackborn getActivity(), android.R.anim.fade_in)); 362445646c52128a763b56ed7bb3bd009e2f33e3e4fDianne Hackborn mListContainer.startAnimation(AnimationUtils.loadAnimation( 363445646c52128a763b56ed7bb3bd009e2f33e3e4fDianne Hackborn getActivity(), android.R.anim.fade_out)); 364afc4b283fdaedec9bf32492a019b43cc33edc9b6Dianne Hackborn } else { 365afc4b283fdaedec9bf32492a019b43cc33edc9b6Dianne Hackborn mProgressContainer.clearAnimation(); 366afc4b283fdaedec9bf32492a019b43cc33edc9b6Dianne Hackborn mListContainer.clearAnimation(); 367445646c52128a763b56ed7bb3bd009e2f33e3e4fDianne Hackborn } 368445646c52128a763b56ed7bb3bd009e2f33e3e4fDianne Hackborn mProgressContainer.setVisibility(View.VISIBLE); 369445646c52128a763b56ed7bb3bd009e2f33e3e4fDianne Hackborn mListContainer.setVisibility(View.GONE); 370445646c52128a763b56ed7bb3bd009e2f33e3e4fDianne Hackborn } 371445646c52128a763b56ed7bb3bd009e2f33e3e4fDianne Hackborn } 372445646c52128a763b56ed7bb3bd009e2f33e3e4fDianne Hackborn 373445646c52128a763b56ed7bb3bd009e2f33e3e4fDianne Hackborn /** 3745ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn * Get the ListAdapter associated with this activity's ListView. 3755ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn */ 3765ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn public ListAdapter getListAdapter() { 3775ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn return mAdapter; 3785ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn } 3795ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn 3805ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn private void ensureList() { 3815ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn if (mList != null) { 3825ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn return; 3835ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn } 3845ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn View root = getView(); 3855ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn if (root == null) { 3865ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn throw new IllegalStateException("Content view not yet created"); 3875ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn } 388445646c52128a763b56ed7bb3bd009e2f33e3e4fDianne Hackborn if (root instanceof ListView) { 389445646c52128a763b56ed7bb3bd009e2f33e3e4fDianne Hackborn mList = (ListView)root; 390445646c52128a763b56ed7bb3bd009e2f33e3e4fDianne Hackborn } else { 391445646c52128a763b56ed7bb3bd009e2f33e3e4fDianne Hackborn mStandardEmptyView = (TextView)root.findViewById( 392445646c52128a763b56ed7bb3bd009e2f33e3e4fDianne Hackborn com.android.internal.R.id.internalEmpty); 393445646c52128a763b56ed7bb3bd009e2f33e3e4fDianne Hackborn if (mStandardEmptyView == null) { 394445646c52128a763b56ed7bb3bd009e2f33e3e4fDianne Hackborn mEmptyView = root.findViewById(android.R.id.empty); 395afc4b283fdaedec9bf32492a019b43cc33edc9b6Dianne Hackborn } else { 396afc4b283fdaedec9bf32492a019b43cc33edc9b6Dianne Hackborn mStandardEmptyView.setVisibility(View.GONE); 397445646c52128a763b56ed7bb3bd009e2f33e3e4fDianne Hackborn } 398445646c52128a763b56ed7bb3bd009e2f33e3e4fDianne Hackborn mProgressContainer = root.findViewById(com.android.internal.R.id.progressContainer); 399445646c52128a763b56ed7bb3bd009e2f33e3e4fDianne Hackborn mListContainer = root.findViewById(com.android.internal.R.id.listContainer); 400445646c52128a763b56ed7bb3bd009e2f33e3e4fDianne Hackborn View rawListView = root.findViewById(android.R.id.list); 401445646c52128a763b56ed7bb3bd009e2f33e3e4fDianne Hackborn if (!(rawListView instanceof ListView)) { 402445646c52128a763b56ed7bb3bd009e2f33e3e4fDianne Hackborn throw new RuntimeException( 403445646c52128a763b56ed7bb3bd009e2f33e3e4fDianne Hackborn "Content has view with id attribute 'android.R.id.list' " 404445646c52128a763b56ed7bb3bd009e2f33e3e4fDianne Hackborn + "that is not a ListView class"); 405445646c52128a763b56ed7bb3bd009e2f33e3e4fDianne Hackborn } 406445646c52128a763b56ed7bb3bd009e2f33e3e4fDianne Hackborn mList = (ListView)rawListView; 407445646c52128a763b56ed7bb3bd009e2f33e3e4fDianne Hackborn if (mList == null) { 408445646c52128a763b56ed7bb3bd009e2f33e3e4fDianne Hackborn throw new RuntimeException( 409445646c52128a763b56ed7bb3bd009e2f33e3e4fDianne Hackborn "Your content must have a ListView whose id attribute is " + 410445646c52128a763b56ed7bb3bd009e2f33e3e4fDianne Hackborn "'android.R.id.list'"); 411445646c52128a763b56ed7bb3bd009e2f33e3e4fDianne Hackborn } 412445646c52128a763b56ed7bb3bd009e2f33e3e4fDianne Hackborn if (mEmptyView != null) { 413445646c52128a763b56ed7bb3bd009e2f33e3e4fDianne Hackborn mList.setEmptyView(mEmptyView); 414afc4b283fdaedec9bf32492a019b43cc33edc9b6Dianne Hackborn } else if (mEmptyText != null) { 415afc4b283fdaedec9bf32492a019b43cc33edc9b6Dianne Hackborn mStandardEmptyView.setText(mEmptyText); 416afc4b283fdaedec9bf32492a019b43cc33edc9b6Dianne Hackborn mList.setEmptyView(mStandardEmptyView); 417445646c52128a763b56ed7bb3bd009e2f33e3e4fDianne Hackborn } 4185ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn } 419445646c52128a763b56ed7bb3bd009e2f33e3e4fDianne Hackborn mListShown = true; 4205ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn mList.setOnItemClickListener(mOnClickListener); 4215ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn if (mAdapter != null) { 422afc4b283fdaedec9bf32492a019b43cc33edc9b6Dianne Hackborn ListAdapter adapter = mAdapter; 423afc4b283fdaedec9bf32492a019b43cc33edc9b6Dianne Hackborn mAdapter = null; 424afc4b283fdaedec9bf32492a019b43cc33edc9b6Dianne Hackborn setListAdapter(adapter); 425ef769f6e4849d5d2580570ce08f9493dd43e7f0dDianne Hackborn } else { 426ef769f6e4849d5d2580570ce08f9493dd43e7f0dDianne Hackborn // We are starting without an adapter, so assume we won't 427ef769f6e4849d5d2580570ce08f9493dd43e7f0dDianne Hackborn // have our data right away and start with the progress indicator. 428ef769f6e4849d5d2580570ce08f9493dd43e7f0dDianne Hackborn if (mProgressContainer != null) { 429ef769f6e4849d5d2580570ce08f9493dd43e7f0dDianne Hackborn setListShown(false, false); 430ef769f6e4849d5d2580570ce08f9493dd43e7f0dDianne Hackborn } 4315ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn } 4325ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn mHandler.post(mRequestFocus); 4335ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn } 4345ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn} 435