diff --git a/samples/ApiDemos/AndroidManifest.xml b/samples/ApiDemos/AndroidManifest.xml
index b191a9fb2..f0c959832 100644
--- a/samples/ApiDemos/AndroidManifest.xml
+++ b/samples/ApiDemos/AndroidManifest.xml
@@ -218,13 +218,6 @@
-
-
-
-
-
-
-
@@ -242,7 +235,14 @@
-
+
+
+
+
+
+
+
+
diff --git a/samples/ApiDemos/res/values/strings.xml b/samples/ApiDemos/res/values/strings.xml
index 20a8fef41..a8f8af223 100644
--- a/samples/ApiDemos/res/values/strings.xml
+++ b/samples/ApiDemos/res/values/strings.xml
@@ -85,8 +85,6 @@
App/Fragment/Anim
- App/Fragment/Complex List
-
App/Fragment/Context Menu
Fragment populating a context
menu; long press the button to see.
@@ -94,7 +92,9 @@
App/Fragment/Layout
- App/Fragment/List
+ App/Fragment/List Array
+
+ App/Fragment/List Cursor Loader
App/Fragment/Menu
Build menus from two fragments, allowing
diff --git a/samples/ApiDemos/src/com/example/android/apis/app/FragmentList.java b/samples/ApiDemos/src/com/example/android/apis/app/FragmentListArray.java
similarity index 86%
rename from samples/ApiDemos/src/com/example/android/apis/app/FragmentList.java
rename to samples/ApiDemos/src/com/example/android/apis/app/FragmentListArray.java
index 1ac8890cf..9dad0306c 100644
--- a/samples/ApiDemos/src/com/example/android/apis/app/FragmentList.java
+++ b/samples/ApiDemos/src/com/example/android/apis/app/FragmentListArray.java
@@ -27,21 +27,22 @@ import android.widget.ArrayAdapter;
import android.widget.ListView;
/**
- * Demonstration of using ListFragment to show a list of items.
+ * Demonstration of using ListFragment to show a list of items
+ * from a canned array.
*/
-public class FragmentList extends Activity {
+public class FragmentListArray extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Create the list fragment and add it as our sole content.
if (findFragmentById(android.R.id.content) == null) {
- ExampleListFragment list = new ExampleListFragment();
+ ArrayListFragment list = new ArrayListFragment();
openFragmentTransaction().add(android.R.id.content, list).commit();
}
}
- public static class ExampleListFragment extends ListFragment {
+ public static class ArrayListFragment extends ListFragment {
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
diff --git a/samples/ApiDemos/src/com/example/android/apis/app/FragmentComplexList.java b/samples/ApiDemos/src/com/example/android/apis/app/FragmentListCursorLoader.java
similarity index 69%
rename from samples/ApiDemos/src/com/example/android/apis/app/FragmentComplexList.java
rename to samples/ApiDemos/src/com/example/android/apis/app/FragmentListCursorLoader.java
index 54d818038..91c54feb1 100644
--- a/samples/ApiDemos/src/com/example/android/apis/app/FragmentComplexList.java
+++ b/samples/ApiDemos/src/com/example/android/apis/app/FragmentListCursorLoader.java
@@ -24,6 +24,7 @@ import android.content.Loader;
import android.database.Cursor;
import android.os.Bundle;
import android.provider.Contacts.Phones;
+import android.provider.ContactsContract.Contacts;
import android.util.Log;
import android.view.View;
import android.widget.ListAdapter;
@@ -34,29 +35,20 @@ import android.widget.SimpleCursorAdapter;
* Demonstration of more complex use if a ListFragment, including showing
* an empty view and loading progress.
*/
-public class FragmentComplexList extends Activity {
+public class FragmentListCursorLoader extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Create the list fragment and add it as our sole content.
if (findFragmentById(android.R.id.content) == null) {
- ExampleComplexListFragment list = new ExampleComplexListFragment();
+ CursorLoaderListFragment list = new CursorLoaderListFragment();
openFragmentTransaction().add(android.R.id.content, list).commit();
}
}
- public static class ExampleComplexListFragment extends ListFragment
+ public static class CursorLoaderListFragment extends ListFragment
implements LoaderManager.LoaderCallbacks {
- boolean mInitializing;
-
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
-
- mInitializing = true;
- }
-
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
@@ -68,18 +60,9 @@ public class FragmentComplexList extends Activity {
// application this would come from a resource.
setEmptyText("No phone numbers");
- // Check if we already have content for the list.
- Loader ld = getLoaderManager().getLoader(0);
- if (ld == null) {
- // No loader started yet... do it now.
- ld = getLoaderManager().startLoading(0, null, this);
- } else {
- // Already have a loader -- poke it to report its cursor
- // if it already has one. This will immediately call back
- // to us for us to update the list right now.
- ld.startLoading();
- }
- mInitializing = false;
+ // Prepare the loader. Either re-connect with an existing one,
+ // or start a new one.
+ getLoaderManager().initLoader(0, null, this);
}
@Override
@@ -92,19 +75,33 @@ public class FragmentComplexList extends Activity {
super.onDestroy();
}
+ static final String[] CONTACTS_SUMMARY_PROJECTION = new String[] {
+ Contacts._ID,
+ Contacts.DISPLAY_NAME,
+ Contacts.CONTACT_STATUS,
+ Contacts.CONTACT_PRESENCE,
+ Contacts.PHOTO_ID,
+ Contacts.LOOKUP_KEY,
+ };
+
@Override
public Loader onCreateLoader(int id, Bundle args) {
- return new CursorLoader(getActivity(), Phones.CONTENT_URI, null, null, null, null);
+ String select = "((" + Contacts.DISPLAY_NAME + " NOTNULL) AND ("
+ + Contacts.HAS_PHONE_NUMBER + "=1) AND ("
+ + Contacts.DISPLAY_NAME + " != '' ))";
+ return new CursorLoader(getActivity(), Contacts.CONTENT_URI,
+ CONTACTS_SUMMARY_PROJECTION, select, null,
+ Contacts.DISPLAY_NAME + " COLLATE LOCALIZED ASC");
}
@Override
public void onLoadFinished(Loader loader, Cursor data) {
ListAdapter adapter = new SimpleCursorAdapter(getActivity(),
android.R.layout.simple_list_item_2, data,
- new String[] { Phones.NAME, Phones.NUMBER },
+ new String[] { Contacts.DISPLAY_NAME, Contacts.CONTACT_STATUS },
new int[] { android.R.id.text1, android.R.id.text2 });
setListAdapter(adapter);
- setListShown(true, !mInitializing);
+ setListShown(true, isResumed());
}
}
}