diff options
| author | Dianne Hackborn <hackbod@google.com> | 2012-05-29 13:58:13 -0700 |
|---|---|---|
| committer | Dianne Hackborn <hackbod@google.com> | 2012-06-04 11:12:37 -0700 |
| commit | 80df91c7f2ac155c1cf4c3337f8db5a4bf5426b5 (patch) | |
| tree | c68c4762a2ff2544d04262a2fbcbd0e95724ab3f /samples/ApiDemos/src/com/example/android/apis/app/LoaderCursor.java | |
| parent | 50d57364f97135906e3acd627d8c3327057d4bb4 (diff) | |
New API demos for retained fragments with loaders.
Also tweak the cursor loader samples to filter out query
callbacks that don't change the filter, to avoid restarting the
loader on a configuration change.
Change-Id: Iac9293fed45e127698be59262d68b0b59a8ec9ce
Diffstat (limited to 'samples/ApiDemos/src/com/example/android/apis/app/LoaderCursor.java')
| -rw-r--r-- | samples/ApiDemos/src/com/example/android/apis/app/LoaderCursor.java | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/samples/ApiDemos/src/com/example/android/apis/app/LoaderCursor.java b/samples/ApiDemos/src/com/example/android/apis/app/LoaderCursor.java index fd2fa6850..f30919146 100644 --- a/samples/ApiDemos/src/com/example/android/apis/app/LoaderCursor.java +++ b/samples/ApiDemos/src/com/example/android/apis/app/LoaderCursor.java @@ -95,7 +95,8 @@ public class LoaderCursor extends Activity { // Place an action bar item for searching. MenuItem item = menu.add("Search"); item.setIcon(android.R.drawable.ic_menu_search); - item.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM); + item.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM + | MenuItem.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW); SearchView sv = new SearchView(getActivity()); sv.setOnQueryTextListener(this); item.setActionView(sv); @@ -105,7 +106,16 @@ public class LoaderCursor extends Activity { // Called when the action bar search text has changed. Update // the search filter, and restart the loader to do a new query // with this filter. - mCurFilter = !TextUtils.isEmpty(newText) ? newText : null; + String newFilter = !TextUtils.isEmpty(newText) ? newText : null; + // Don't do anything if the filter hasn't actually changed. + // Prevents restarting the loader when restoring state. + if (mCurFilter == null && newFilter == null) { + return true; + } + if (mCurFilter != null && mCurFilter.equals(newFilter)) { + return true; + } + mCurFilter = newFilter; getLoaderManager().restartLoader(0, null, this); return true; } |
