I\'ve followed this Android guide in order to add a search bar to an activity. The setup looks like this:
res/menu/activity_main.xml:
Add it to the activity where you've put your SearchView
<meta-data
android:name="android.app.default_searchable"
android:value=".activity_that_handles_the_search" />
<intent-filter>
<action android:name="android.intent.action.SEARCH" />
</intent-filter>
Replace:
android:actionViewClass="android.widget.SearchView"
With:
app:actionViewClass="android.widget.SearchView"
Because app
is often used if you are using support library.
In my case the problem was my mistake during integration with ActionBarSherlock. In this case android:actionViewClass
should be com.actionbarsherlock.widget.SearchView
instead of android.widget.SearchView
. I know this sounds dumb, but I spent 20 minutes trying to figure out why searchView
is null
in my code that is similar to yours.