October 2019
Intermediate to advanced
624 pages
20h 7m
English
For a little bit of polish, pre-populate the search text box with the saved query when the user presses the search icon to expand the search view.
First, add a computed property to PhotoGalleryViewModel to expose the search term the UI is currently displaying results for.
Listing 26.15 Exposing the search term from PhotoGalleryViewModel (PhotoGalleryViewModel.java)
class PhotoGalleryViewModel(private val app: Application) : AndroidViewModel(app) {
...
private val mutableSearchTerm = MutableLiveData<String>()
val searchTerm: String
get() = mutableSearchTerm.value ?: ""
init {
...
}
...
}
SearchView’s View.OnClickListener.onClick() function is called when the user presses the search icon. Hook into this callback ...
Read now
Unlock full access