The challenge cause me to read through the Search Overview topic, because I can only get it to work for pre-API 11 (Search Dialog). It would seem the SearchView implementation is different.
PhotoGalleryActivity.onNewIntent() - gets called for both search types.
PhotoGalleryActivity.onSearchRequested() - where I call the [color=#BF0040]startSearch(query, true, null, false);[/color] method for the challenge, only gets called by the Search Dialog thing.
The android overview does not address doing both implementations well, like in how you have a item with two icons but then superimpose the SearchView into the Action Bar. I am still confused about how to best code for both methods for the two API targets. I don’t think the challenge is possible for the SearchView method.
The SearchView has its own ICON for cancel. So, I think you would want to remove the MenuItem for it when using a SearchView:
MenuItem cancelItem = menu.findItem(R.id.menu_item_clear);
The overview also said to do this (so you can initiate the search either from the keyboard or from the SearchView):
If you add this:
the app starts with the SearchView visible and the menu_item_search not visible. Otherwise, you see the menu_item_search, and when you click it you see the SearchView. I am guessing that the menu_item_search goes away because it no longer fits in the action bar. Someone else posted something about this in this forum in May, but you ignored it.
I tried to make this only occur for API < 11:
but then got a NullPointerException for this:
So, I think this chapter is really sloppily done. It should provide at least as much info as the Android overview. I think that inflating a menu with two ICONs and then just laying the SearchView on top of it is the wrong way to go. It should be one or the other. Not both.
If you restart the app, the SearchView will start out with the hint text but the app will then continue to do a new search from the saved query. I can’t see any way to get the SearchView to display the saved query string.
Also, the SearchView’s clear button (X) just clears the text in it. It does not call onOptionsItemSelected with menu_item_clear, allowing you to also remove the query from the persisted storage.
For the Search Dialog solution of pre-API-11, the app will still go back to doing the getRecents() thing when the clear button is pressed.
The two different behaviors of the clear button don’t make sense.