I'm not unsure of why I'm getting this error. Here's the menu in question:
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
tools:context="com.example.myapp.MainActivity" >
<item
android:id="@+id/action_search"
android:icon="@drawable/ic_action_search"
android:title="@string/action_search"
android:showAsAction="collapseActionView|ifRoom"
android:actionViewClass="android.widget.SearchView" />
<item
android:id="@+id/action_settings"
android:orderInCategory="100"
android:title="@string/action_settings"
app:showAsAction="never"/>
Here's the searchable configuration as per the developer guide.
<?xml version="1.0" encoding="utf-8"?>
<searchable xmlns:android="http://schemas.android.com/apk/res/android"
android:label="@string/app_name"
android:hint="@string/search_hint" >
</searchable>
Added to my manifest file:
<meta-data
android:name="android.app.searchable"
android:resource="@xml/searchable" />
I also have an intent handler in the new search activity. Why is this error showing up? My min sdk is 11.
EDIT
In onCreateOptionsMenu:
// Associate searchable config with the SearchView
SearchManager searchManager =
(SearchManager) getSystemService(Context.SEARCH_SERVICE);
SearchView searchView =
(SearchView) menu.findItem(R.id.action_search).getActionView();
searchView.setSearchableInfo(
searchManager.getSearchableInfo(getComponentName()));
return true;
In the menu.xml your <item></item> has to be
<item
android:id="@+id/action_search"
android:icon="@drawable/ic_action_search"
android:title="@string/action_search"
android:showAsAction="collapseActionView|ifRoom"
android:actionViewClass="android.support.v7.widget.SearchView" />
with that change in the last line
you should use these imports instead of using the support library imports
import android.app.SearchManager;
import android.widget.SearchView;
import android.widget.SearchView.OnQueryTextListener;
Just to keep in mind that the minimum SDK is marked as 14
Find import android.widget.SearchView;
in your imports and replace it with import android.support.v7.widget.SearchView
Try adding this:
MenuItem menuItem = menu.findItem(R.id.action_search);
SearchView searchView = (SearchView) MenuItemCompat.getActionView(menuItem);
It worked for me.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With