I write a simple messenger. I have such a form with dialogs:
After I enter the name of the new interlocutor in the search and I choose it, then I move to a new Activity I can correspond. The problem is that when I return to Activity with dialogues, there is still a search phrase with the login, the interlocutor, whom we have been looking for before. That is, so:
So this is the question: how do I close / kill this search string when you return to Activity with dialogs?
// *********
I have such a markup:
& lt; xml version = "1.0" encoding = "UTF-8"? & gt;
& lt; Menu XMLNS: Android = "http://schemas.android.com/apk/res/android"
XMLNS: App = "http://schemas.android.com/apk/res-auto" & gt;
& lt; item
Android: id = "@ + ID / Action_Search"
Android: icon = "@ Android: Drawable / Ic_Menu_Search"
App: ShowasAction = "Always"
App: ActionViewClass = "Android.Support.v7.widget.SearchView"
Android: title = "@ STRING / SEARCH_TITLE" / & GT;
& lt; / menu & gt;
Answer 1, Authority 100%
private searchview searchview;
@Override
Public Boolean OnCreateOptionsMenu (Menu Menu) {
...
Menuitem searchmenuitem = menu.finditem (R.ID.Action_Search);
SearchView = (SearchView) searchMenuitem.getActionView ();
...
}
@Override
Public void onresume () {
super.onresume ();
searchview.setQuery ("", false);
searchview.clearfocus ();
searchview.seticonified (TRUE); // If you need not only to clean, but also roll
}
Answer 2, Authority 80%
private searchview searchview;
@Override
Public Boolean OnCreateOptionsMenu (Menu Menu) {
// Initialization of your searchView
}
@Override
Public void onresume () {
super.onresume ();
If (SearchView! = NULL & AMP; & AMP;! searchview.isiconified ()) {
searchview.setQuery ("", false);
searchview.clearfocus ();
searchview.seticonified (TRUE);
}
}