I have created a search interface but I can't seem to connect the SearchView
in the ActionBar
to my searchable configuration file. When I try to retreive it in my onCreateOptionsMenu
method SearchManager.getSearchableInfo(getComponentName()
returns null. Could someone help me out with this?
Settings.onCreateOptionsMenu(Menu)
@Override
public boolean onCreateOptionsMenu(Menu menu) {
super.onCreateOptionsMenu(menu);
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.activity_main, menu);
SearchManager sm = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
SearchView sv = (SearchView) menu.findItem(R.id.menu_search).getActionView();
SearchableInfo info = sm.getSearchableInfo(getComponentName()); //This variable is returned as null
sv.setSearchableInfo(info);
sv.setIconifiedByDefault(false);
sv.setSubmitButtonEnabled(true);
return true;
}
Settings Activity in AndroidManifest.xml
<activity
android:name=".Settings"
android:label="@string/app_name"
android:screenOrientation="portrait" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<meta-data
android:name="android.app.searchable"
android:resource="@xml/searchable" />
</activity>
Searchable Activity in AndroidManifest.xml
<activity
android:name=".ImageSearch"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.SEARCH" />
</intent-filter>
</activity>
I have the header <?xml version="1.0" encoding="utf-8"?>
in my menu xml file and I tried cleaning the project. None of them seem to do the trick.