3

Hi the search widget in the action bar of my application is not displaying the default text for some reason. I am sure I might be missing something. The code looks like below:-

 @Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.activity_main, menu);
    try{
        SearchView searchView = (SearchView) menu.findItem(R.id.action_search).getActionView();
        searchView.setOnQueryTextListener(this);
        }catch(Exception e){
            Log.v(TAG,"inflated"+e.getMessage()+"--"+e.getClass()+"-"+e.getClass());
        }
    return true;
}

menu/activity_main

<menu xmlns:android="http://schemas.android.com/apk/res/android">

   <item android:id="@+id/action_search"
      android:title="@string/search_title"
      android:icon="@android:drawable/ic_menu_search"
      android:showAsAction="ifRoom|collapseActionView"
      android:actionViewClass="android.widget.SearchView" />
 </menu>

values/strings.xml

<resources>
<string name="search_title">Search Data</string>
</resources>

The search widget is working perfectly , the only thing is the default text "Search Data" is not showing.. Can someone tell me what am I doing wrong

4

1 に答える 1

5

Try to use this

searchView.setQueryHint(getResources().getString(R.string.search_title));
于 2012-09-05T12:32:51.690 に答える