after some time playing "run and error" I found a solution. It seems that the user interface is not the cause of the error. After setting the search to QueryListener, it works well. Here is the code:
Activity that contains SearchBar:
@Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.menu_main, menu); SearchView searchView = (SearchView) menu.findItem(R.id.search).getActionView(); searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() { @Override public boolean onQueryTextSubmit(String s) { Log.d(TAG, "onQueryTextSubmit "); return false; } @Override public boolean onQueryTextChange(String s) { Log.d(TAG, "onQueryTextChange "); return false; } }); return true; }
searchable.xml
<searchable xmlns:android="http://schemas.android.com/apk/res/android" android:label="@string/app_name" android:hint="@string/search_hint"/>
And the "SearchBar" in menu.xml
<item android:id="@+id/search" android:title="@string/search_title" android:icon="@drawable/abc_ic_search_api_mtrl_alpha" app:showAsAction="collapseActionView|ifRoom" app:actionViewClass="android.support.v7.widget.SearchView"/> ...
And last but not least, the manifest (but that should be clear) ...
<activity android:name=".activities.MainActivity" android:label="@string/title_activity_main"> <meta-data android:name="android.app.searchable" android:resource="@xml/searchable"/> </activity>
Additional information → Documents
Martin Pfeffer Mar 03 '15 at 13:01 2015-03-03 13:01
source share