There are 2 fragments on the activity:

  1. SearchFragment : search bar and button.
  2. ListFragment with search results.

When you click on the button from the SearchFragment via callback, the method in activation is run. Next you need to find a list of items from SQLite and display it in a ListFragment . The search is rendered into the method of a separate class DBHelper.SearchItems(String searchString) .

I can not figure out what and in what places you need to do: from search to listFragment , get the cursor and transfer it to the listFragment or transfer the search string to the listFragment , search in the fragment?

  • In DBHelper, add a listen function and subscribe to it in the ListFragment. When searching from SearchFragment, call SearchItems, and from there send the result to all subscribers. - Deadkenny
  • I consider that it is necessary to search in ListFragment, but not in Activity. If, of course, the received request data will be used only in this ListFragment. The fragment has all the necessary hooks to correctly initialize and destroy the cursor in time. Activity will not be overloaded with unnecessary code. This ListFragment can be reused with this search. It may even make sense to move the cursor in the retained fragment, or use loaders to save it correctly when the screen rotates. - lsillarionov
  • Initially, the listFragment is not added to the activation, so there is no one to listen to. In all books, the search is implemented in onCreate, but they are searched throughout the database. How then to transfer the search phrase there? - dantrag10
  • Created a singlet class with a query string and a link to a database. Search onCreate - dantrag10

0