diff options
author | Dianne Hackborn <hackbod@google.com> | 2010-07-12 11:40:53 -0700 |
---|---|---|
committer | Dianne Hackborn <hackbod@google.com> | 2010-07-12 17:45:51 -0700 |
commit | ef769f6e4849d5d2580570ce08f9493dd43e7f0d (patch) | |
tree | b445d288e0899a8bcf9fb60dd8cd98aba5c3173e /core/java/android | |
parent | 8335619363c6cc0f14ab78d2806dbbddb2cacb30 (diff) | |
download | frameworks_base-ef769f6e4849d5d2580570ce08f9493dd43e7f0d.zip frameworks_base-ef769f6e4849d5d2580570ce08f9493dd43e7f0d.tar.gz frameworks_base-ef769f6e4849d5d2580570ce08f9493dd43e7f0d.tar.bz2 |
Some improvements to ListFragment.
- Take care of hiding/showing list automatically for normal behavior.
- Make list_content public for others to use.
Change-Id: Iecb7b70775d390d4e28e5c0dd6ba7278581b2734
Diffstat (limited to 'core/java/android')
-rw-r--r-- | core/java/android/app/ListActivity.java | 2 | ||||
-rw-r--r-- | core/java/android/app/ListFragment.java | 48 |
2 files changed, 47 insertions, 3 deletions
diff --git a/core/java/android/app/ListActivity.java b/core/java/android/app/ListActivity.java index 4bf5518..d49968f 100644 --- a/core/java/android/app/ListActivity.java +++ b/core/java/android/app/ListActivity.java @@ -309,7 +309,7 @@ public class ListActivity extends Activity { if (mList != null) { return; } - setContentView(com.android.internal.R.layout.list_content); + setContentView(com.android.internal.R.layout.list_content_simple); } diff --git a/core/java/android/app/ListFragment.java b/core/java/android/app/ListFragment.java index 96485f7..73ef869 100644 --- a/core/java/android/app/ListFragment.java +++ b/core/java/android/app/ListFragment.java @@ -172,11 +172,17 @@ public class ListFragment extends Fragment { * is {@link android.R.id#list android.R.id.list} and can optionally * have a sibling view id {@link android.R.id#empty android.R.id.empty} * that is to be shown when the list is empty. + * + * <p>If you are overriding this method with your own custom content, + * consider including the standard layout {@link android.R.layout#list_content} + * in your layout file, so that you continue to retain all of the standard + * behavior of ListFragment. In particular, this is currently the only + * way to have the built-in indeterminant progress state be shown. */ @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { - return inflater.inflate(com.android.internal.R.layout.list_content_rich, + return inflater.inflate(com.android.internal.R.layout.list_content, container, false); } @@ -217,9 +223,15 @@ public class ListFragment extends Fragment { * Provide the cursor for the list view. */ public void setListAdapter(ListAdapter adapter) { + boolean hadAdapter = mAdapter != null; mAdapter = adapter; if (mList != null) { mList.setAdapter(adapter); + if (!mListShown && !hadAdapter) { + // The list was hidden, and previously didn't have an + // adapter. It is now time to show it. + setListShown(true, getView().getWindowToken() != null); + } } } @@ -276,12 +288,38 @@ public class ListFragment extends Fragment { * displayed if you are waiting for the initial data to show in it. During * this time an indeterminant progress indicator will be shown instead. * + * <p>Applications do not normally need to use this themselves. The default + * behavior of ListFragment is to start with the list not being shown, only + * showing it once an adapter is given with {@link #setListAdapter(ListAdapter)}. + * If the list at that point had not been shown, when it does get shown + * it will be do without the user ever seeing the hidden state. + * + * @param shown If true, the list view is shown; if false, the progress + * indicator. The initial value is true. + */ + public void setListShown(boolean shown) { + setListShown(shown, true); + } + + /** + * Like {@link #setListShown(boolean)}, but no animation is used when + * transitioning from the previous state. + */ + public void setListShownNoAnimation(boolean shown) { + setListShown(shown, false); + } + + /** + * Control whether the list is being displayed. You can make it not + * displayed if you are waiting for the initial data to show in it. During + * this time an indeterminant progress indicator will be shown instead. + * * @param shown If true, the list view is shown; if false, the progress * indicator. The initial value is true. * @param animate If true, an animation will be used to transition to the * new state. */ - public void setListShown(boolean shown, boolean animate) { + private void setListShown(boolean shown, boolean animate) { ensureList(); if (mProgressContainer == null) { throw new IllegalStateException("Can't be used with a custom content view"); @@ -356,6 +394,12 @@ public class ListFragment extends Fragment { mList.setOnItemClickListener(mOnClickListener); if (mAdapter != null) { setListAdapter(mAdapter); + } else { + // We are starting without an adapter, so assume we won't + // have our data right away and start with the progress indicator. + if (mProgressContainer != null) { + setListShown(false, false); + } } mHandler.post(mRequestFocus); } |