Search Functionality in RecyclerView using EditText

In this post we will learn adding Search Functionality in RecyclerView. If a list contain many items then giving a search option is really necessary for making it user friendly. So lets see how to add Search Functionality in RecyclerView.

Creating a RecyclerView

Creating new Project

  • The very first thing we need is the RecyclerView itself. Only then we can add the search. So lets create a new Android Studio Project.

Adding RecyclerView and CardView

  • Once you have created a new Android Studio Project add RecyclerView and CardView to it. If you don’t know adding RecyclerView and CardView you can refer to the previous RecyclerView Tutorial.

Creating Layouts

  • Now once you have added the project come inside activity_main.xml and create a RecyclerView. The code for my activity_main.xml is below.

  • The above code will produce the following layout.

search functionality in recyclerview

  • As you can see have a RecyclerView and an EditText. When we type something on EditText the RecyclerView will get filtered.
  • Now we will create a layout for our List Item. So create a new Layout Resource file named list_layout.xml and write the following xml code.

Creating RecyclerView Adapter

  • Now we will create Adapter for our RecyclerView. So create a class named CustomAdapter and write the following code.

  • Now come to and write the following code.

  • Now run the application and you will see your RecyclerView.

search functionality in recyclerview

  • As you can see we have the RecyclerView. Now we will implement Search Functionality in RecyclerView.

Implementing Search Functionality in RecyclerView

  • Come to and add a TextChangedListener as shown below. You have to do this inside onCreate().

  • Now we need to create the method filter().

  • Lastly we need to create the method filter inside CustomAdapter class. So come inside and define the following method.

  • Now run the application and try searching.

search functionality in recyclerview

  • Bingo! It is working absolutely fine.

So we have the Search Functionality in RecyclerView. Thats all for this tutorial. If you are having any confusions or queries then lets have a discussion on comment section. Also don’t forget to SHARE the post if you found it useful. Thank You 🙂

33 thoughts on “Search Functionality in RecyclerView using EditText”

  1. hello sir,Nice tutorial its working fine.

    I want to do search option for the data which is loaded from the database.

  2. Hello, thanks for the excellent tutorial. It’s working. Now I would like to know how to make the same with pair list like this one List<Pair>, ie: example of recyclerView giving the name and some description.

  3. What if am performing search from a List array with values such as first name, second name, etc .. your example is ding it from a single array list with single value names.. how would go about it? Your response would rely be appreciated.. Thanx

  4. hai sir
    can u give me idea
    how to search data by using multiple strings
    for example rajasekar,bangalore like that
    addTextChangeListener allow only one String even it should not allow space

  5. Hello Sir, I am populating my recyclerView from mysql database. So, the searching is not working.

    private void filter(String text) {
    //new array list that will hold the filtered data
    List filterdNames = new ArrayList();

    //looping through existing elements
    for (ModelUpdateModerator s : updateModeratorList) {
    //if the existing elements contains the search input
    if (s.toLowerCase().contains(text.toLowerCase())) {
    //adding the element to filtered list

    //calling a method of the adapter class and passing the filtered list

    error in toLowerCase(). I know because its not string. But I can’t find any solution.

  6. Very Helpful Tutorial!! This tutorial searches in one RecyclerView in the same Activity using EditText..
    Can you please suggest how to use the EditText or SearchView to search for items in different Activities..
    I have seven RecyclerViews, in seven separate Activities.. I want to filter the results for items in all the RecyclerViews of my Activities..

    What changes i have to make to the CustomAdapter class or to the filter() method, and also to the MainActivity class as suggested by you in this tutorial..

    Hope you understood my problem… If you could mail me the suggestion .. it would be of great help to me…
    my mail id is ..

  7. here the method of adapter can not be called within mainActivity.
    i have created a object for adapter in mainActivity but it doesnot call the adapter filter method.please help…..

  8. Even all the anroid tutorial could not let me know how can i implement search functionlaity in Recyclerview. You did it man. Its is workig.

    Million Thanks to you.

    BTW — I am working on a project. Myself is an android developer building my own app and to set up my company. If you have in depth knowledge and want to work as a freelancer kindly contact me.


Leave a Comment