Home java how to close the search in Toolbar

how to close the search in Toolbar

Author

Date

Category

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);
  }
}

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions