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! ;)
You might also try the following:
searchView.setQuery("", false); searchView.clearFocus();
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