I'm having a strange issue(for me at least). my app works fine with debug apk. but when I create release apk then it shows error in searchwidget. I'm using support library 'com.android.support:appcompat-v7:21.0.3'
this is my code
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// TODO Auto-generated method stub
MenuInflater mi = getMenuInflater();
mi.inflate(R.menu.searchmenu, menu);
SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
final MenuItem searchItem = menu.findItem(R.id.searchwidget);
final SearchView searchView = (SearchView) MenuItemCompat
.getActionView(searchItem);
if(null!=searchManager ) {
searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
}
searchView.setIconifiedByDefault(false);
SearchView.OnQueryTextListener textChangeListener = new SearchView.OnQueryTextListener() {
@Override
public boolean onQueryTextChange(String newText) {
// this is your adapter that will be filtered
Programs.this.adapter.getFilter().filter(newText);
return true;
}
@Override
public boolean onQueryTextSubmit(String query) {
// this is your adapter that will be filtered
Programs.this.adapter.getFilter().filter(query);
return true;
}
};
searchView.setOnQueryTextListener(textChangeListener);
return super.onCreateOptionsMenu(menu);
}
my menu code
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:title="@string/search"
android:id="@+id/searchwidget"
app:showAsAction="always|collapseActionView"
android:icon="@drawable/ic_action_search"
app:actionViewClass="android.support.v7.widget.SearchView"></item>
</menu>
first I thought it is proguard problem therefore i used this
-keepclassmembers class android.support.v7.widget.SearchView{
}
but still same problem.
can anyone explain why this is happening?
To add a SearchView widget to the app bar, create a file named res/menu/options_menu. xml in your project and add the following code to the file. This code defines how to create the search item, such as the icon to use and the title of the item.
SearchView widget can be implemented over ToolBar/ActionBar or inside a layout. SearchView is by default collapsible and set to be iconified using setIconifiedByDefault(true) method of SearchView class. For making search field visible, SearchView uses setIconifiedByDefault(false) method.
Invoking the search dialog For instance, you should add a Search button in your Options Menu or UI layout that calls onSearchRequested() . For consistency with the Android system and other apps, you should label your button with the Android Search icon that's available from the Action Bar Icon Pack.
You have to add
-keep class android.support.v7.widget.SearchView { *; }
to proguard-rules.pro file.
Somehow it is related to proguard obfuscation, probably a bug in SearchView. (some version affected, some not)
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