I want to implement SearchView with multiple fragments present in a viewPager. All fragemnts contains lists and I want to filter those lists and create a new ListView which has
If You wanna search your query to all fragment must use Viewmodel with Livedata. Set Your Query in Livedata then Your Livedata Observe on all Your Fragment.
This Code in viewPager side
val searchLiveData = MutableLiveData()
searchLiveData.postValue("query")
This code in all Fragments
mainViewModel.searchLiveData.observe(viewLifecycleOwner, Observer { query ->
//Add your code
})
//1
val liveData: MutableLiveData()
//2
liveData.value = "Hello"
//3
liveData.observe(this, Observer {
// Update UI
})