Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Resetting Search Widget (SearchView) value

I've got 2 activites : the first, HomepageActiviy, have a search widget that search data using another activity, SearchActivity.

What I want to do is when I go back from SearchActiviy to HomepageActivity, the search widget go collapsed and with a empty text.

I've tried to do this following thing :

public class HomepageActivity extends Activity {     @TargetApi(11)     @Override     public boolean onCreateOptionsMenu(Menu menu) {         MenuInflater inflater = getMenuInflater();         inflater.inflate(R.menu.projectslist, menu);          if(Build.VERSION.SDK_INT >= 11) {             SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);             SearchView searchView = (SearchView) menu.findItem(R.id.homepage_search).getActionView();             ComponentName component = new ComponentName(this, SearchActivity.class);             searchView.setSearchableInfo(searchManager.getSearchableInfo(component));             searchView.setIconifiedByDefault(true);             searchView.setQuery("", false);          }          return super.onCreateOptionsMenu(menu);     }      […]      @TargetApi(11)     @Override     protected void onRestart() {         super.onRestart();         if(Build.VERSION.SDK_INT >= 11)             invalidateOptionsMenu();         launchAsynchronousImageDownload();     } } 

If the widget is well displayed as collapsed, the text in the widget still remember searched text (after I re-open the widget). How can I reset the text of the widget?

Thanks for any help! ;)

like image 502
Kyriog Avatar asked Oct 30 '12 15:10

Kyriog


1 Answers

You might also try the following:

searchView.setQuery("", false); searchView.clearFocus(); 
like image 140
BJV Avatar answered Oct 05 '22 20:10

BJV