What is: Activity , the whole part of the space of which is occupied by two Fragment (alternately). The first Fragment contains a SearchView search widget and a list based on RecyclerView . By clicking on the list item, the first Fragment is changed to the second. The second Fragment will contain only a list (other) based on RecyclerView .

What you need to do: By clicking on the Back Button (back), you need the Activity to first roll back the stack in the FragmentManager by calling popBackStack() , then when only the initial (first) Fragment remains, you need to close the Activity

Problem: Obviously, because of the focus on SearchView , the Back Button does not work, respectively, OnBackPressed() with the entire OnBackPressed() on rollback of the stack is not called in the Activity . Google’s long hours suggested that the SearchView is only a Toolbar’s kosher place, but this is not a valid solution for several reasons:

  1. I want to have a widget in Fragment 'e;
  2. Of all, only the logic on the "back" key does not work;
  3. There are plans to transfer both Fragment 'a to BottomSheet to a completely different Activity , in which the search widget in the Toolbar will be out of place.

I need help with solving a problem, or another search widget, if suddenly I missed it.

  • That is, in fact, the "back" button does not work for you, and the question is called "Search in Fragment", although there are no problems with the implementation, in fact, there is no search .. - pavlofff
  • @pavlofff The problem with the search widget, I did not indicate in the title of the question the problems with the search process - Roman Vasilyev

0