eclipse - Why is android.R.menu_search giving me an error? -
i'm trying add search widget action bar , reason i'm getting "android.r.menu_search cannot resolved or not field". code i'm using
@override public boolean oncreateoptionsmenu(menu menu) { // inflate menu; adds items action bar if present. getmenuinflater().inflate(r.menu.geolocation_search, menu); //get searchview , set searchable configuration searchmanager searchmanager = (searchmanager) getsystemservice(context.search_service); searchview searchview = (searchview) menu.finditem(android.r.layout.menu_search).getactionview(); //assumes current activity searchable activity searchview.setsearchableinfo(searchmanager.getsearchableinfo(getcomponentname())); //searchview.seticonifiedbydefault(false); return true; }
the xml file
<menu xmlns:android="http://schemas.android.com/apk/res/android" > <item android:id="@+id/action_settings" android:orderincategory="100" android:showasaction="never" android:title="@string/action_settings"/> <item android:id="@+id/headers" android:showasaction="always|withtext" android:title="@string/header1"/> <item android:id="@+id/menu_search" android:actionviewclass="android.widget.searchview" android:icon="@android:drawable/ic_menu_search" android:showasaction="always" android:title="@string/search"/> </menu>
so, doing wrong?
if have own menu xml can't read android's identifiers yours. issue resolved replacing
searchview searchview = (searchview) menu.finditem(android.r.layout.menu_search).getactionview();
with
searchview searchview = (searchview) menu.finditem(r.id.menu_search).getactionview();
Comments
Post a Comment