This is the second part of the complete mini course on RecyclerView. In this tutorial, I will show you step by step how to implement SearchView widget to filter a RecyclerView in real time using Kotlin. We will add the SearchView as an item to our options menu and make it expandable with the help of collapseActionView attribute. We will have a search icon in our action bar which will expand to an input when we click on the search icon. Then, in our Main Activity we will connect our SearchView with the Filter by setting an OnQueryTextListener onto our SearchView and listening for the text input in onQueryTextChange. We will also handle errors such as empty keywords or nonexcited keywords.
About RecyclerView
The RecyclerView is a ViewGroup that renders any adapter-based view in a similar way. It is supposed to be the successor of ListView and GridView. One of the reasons is that RecyclerView has a more extensible framework, especially since it provides the ability to implement both horizontal and vertical layouts. Use the RecyclerView widget when you have data collections whose elements change at runtime based on user action or network events.
🔴 Subscribe for more educational tutorials on CodeWithMazn channel!
Follow me on Instagram
/ codewithmazn