Android Action Bar SearchView NullPointerException adjustDropDownSizeAndPosition -
the problem occurs when interacting searchview or when activity searchview loads. when using seticonifiedbydefault(true)
problem occurs after activity loads when interacting searchview, when using seticonifiedbydefault(false)
problem occurs when activity loads.
the following error output in logcat:
java.lang.nullpointerexception @ android.widget.searchview.adjustdropdownsizeandposition(searchview.java:1244)
here code:
exampleactivity.java
public boolean oncreateoptionsmenu(menu menu) { getmenuinflater().inflate(r.menu.example, menu); if(build.version.sdk_int >= build.version_codes.honeycomb) { searchmanager manager = (searchmanager) getsystemservice(context.search_service); searchview search = (searchview) menu.finditem(r.id.search).getactionview(); search.setsearchableinfo(manager.getsearchableinfo(getcomponentname())); search.seticonifiedbydefault(true); search.setonquerytextlistener(new onquerytextlistener() { @override public boolean onquerytextsubmit(string query) { // perform search return true; } }); } return true; }
menu/example.xml
<menu xmlns:android="http://schemas.android.com/apk/res/android"> <item android:id="@+id/search" android:title="search" android:showasaction="ifroom" android:actionviewclass="android.widget.searchview" /> </menu>
xml/searchable.xml
<searchable xmlns:android="http://schemas.android.com/apk/res/android" android:label="@string/search" android:hint="@string/search" > </searchable>
the "search" string used in searchable.xml defined in values/strings.xml. searchable.xml file referenced correctly in activity tag in androidmanifest.xml:
<meta-data android:name="android.app.default_searchable" android:value="com.example.mainactivity" /> <meta-data android:name="android.app.searchable" android:resource="@xml/searchable" />
this problem caused styles being applied edittext
in action bar searchview
.
you can fix removing style have applied edittext
such as:
res/values/styles.xml
<item name="android:edittextstyle">@style/editor</item>
then go each edittext
view in layout xml , apply style directly:
<edittext style="@style/editor" />
Comments
Post a Comment