Search Result List View

LAST EDIT Mar 05 2021

SearchResultListView is a widget that displays a list of search results:

SearchResultListView

Adding the layout

Copied!
1
2
3
4
<io.getstream.chat.android.ui.search.list.SearchResultListView 
    android:id="@+id/searchResultListView" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" />

Binding with a ViewModel

Copied!

SeachResultListView comes with SearchViewModel which is responsible for providing all needed data. The view can be bound with it using:

1
2
3
4
// Get ViewModel 
val viewModel: SearchViewModel by viewModels() 
// Bind it with SearchResultListView 
viewModel.bindView(searchResultListView, this)
1
2
3
4
// Get ViewModel 
SearchViewModel viewModel = new ViewModelProvider(this).get(SearchViewModel.class); 
// Bind it with SearchResultListView 
SearchViewModelBinding.bind(viewModel, searchResultListView, this);

After the SeachResultListView is bound to the SearchViewModel, the search can be triggered with the setQuery method. In the example below, the search query comes from SearchInputView:

1
2
3
searchInputView.setSearchStartedListener { query -> 
    viewModel.setQuery(query) 
}
1
2
3
searchInputView.setSearchStartedListener(query -> { 
    viewModel.setQuery(query); 
});