Reputation: 1675
I'm following this guide to add an actionbar SearchView widget to my activity: http://developer.android.com/training/search/setup.html
I've got it working except on this page: http://developer.android.com/training/search/backward-compat.html it says that "only versions older than 3.0 call onOptionsItemSelected() when the user selects the search menu item" so I can call onSearchRequested() in onOptionsItemSelected when this search button is pressed for older devices. But when I test that on Jellybean, I press the search button and it expands the searchview but also opens a search dialog over, so I have two search widgets on top of each other.
It seems like onOptionsItemSelected() is still being called when the search button is pressed on a 3.0+ device, but the guide says otherwise. Am I implementing it wrong? I tried making a new project and following the guide exactly, and it has the same behaviour.
Upvotes: 1
Views: 1338
Reputation: 1675
This was a misinterpretation on my part. I thought the documentation was saying that the hardware search button would not trigger onOptionsItemSelected and would instead expand the searchView. But it actually just says that the search menu option will not trigger onOptionsItemSelected
To fix this I overrode onSearchRequested and expanded the searchView there
Upvotes: 1