Search News Fragment
Learn how to implement search functionality in our application.
We'll cover the following
Searching our data
We will implement an Android search widget in our fragment, allowing the user to search for articles by typing in a query. When the search is executed, the query will be sent to a function for processing, and the search will be performed.
Implementing search functionality
We’ll implement a search feature that allows users to search for specific articles by typing in the source, publishing company, or author’s name. This is done by subscribing to an observer in the ViewModel
and passing the latest data as a search query
to the searchNews()
method within a coroutine. The searchNews()
method takes in a search query
as one of its arguments and uses it to request the API to perform the desired search.
Get hands-on with 1400+ tech skills courses.