summaryrefslogtreecommitdiff
path: root/samples/ApiDemos/src/com/example/android/apis/app/LoaderCursor.java
diff options
context:
space:
mode:
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.java14
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;
}