VOOZH about

URL: https://www.geeksforgeeks.org/android/searchview-in-android-with-recyclerview/

⇱ SearchView in Android with RecyclerView - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

SearchView in Android with RecyclerView

Last Updated : 23 Jul, 2025

Many apps represent data in the form of huge lists and for filtering these lists we have seen the SearchView present inside these apps. So for filtering this list of data we generally use a SearchView. In this article, we will take a look at the implementation of Search View in Android with a RecyclerView in Android. 

What are We Going to Build in this Article? 

We will be building a simple application in which we will display a list of data in the RecyclerView. We will be displaying the list of courses with its description and on that recycler view, we will add a SearchView which will be used to filter the data in our Recycler View. A sample video is given below to get an idea about what we are going to do in this article.

Step-by-Step Implementation

Step 1: Create a New Project in Android Studio

To create a new project in Android Studio please refer to How to Create/Start a New Project in Android Studio.

The code for that has been given in both Java and Kotlin Programming Language for Android.

Step 2: Working with the XML Files

Next, go to the activity_main.xml file, which represents the UI of the project. Below is the code for the activity_main.xml file. Comments are added inside the code to understand the code in more detail.

activity_main.xml:


Step 3: Creating a Model Class for Storing Our Data

Navigate to the app > java > your app's package name > Right-click on it > New > Java/Kotlin class and name your class as CourseModel and add the below code to it.

CourseModel File:


Step 4: Creating a Layout File for Our Item of RecyclerView

Navigate to the app > res > layout > Right-click on it > New > layout resource file and name your layout as course_rv_item and add the below code to it.

course_rv_item.xml:


Step 5: Creating an Adapter Class for Setting Data to Items of Our RecyclerView

Navigate to the app > java > your app's package name > Right-click on it > New > Java/Kotlin class and name it as CourseAdapter and add the below code to it.

CourseAdapter File:


Step 6: Creating a Menu File for Our SearchView

Navigate to the app > res > Right-click on it > New > Directory and give a name to your directory as the menu. After creating a new directory we have to create a new menu file inside it. For creating a new menu file. Navigate to the app > res > menu > Right-click on it > New > menu resource file, name it as search_menu and add the below code to it. 

search_menu.xml:


Step 7: Working with the MainActivity File

Go to the MainActivity File and refer to the following code. Below is the code for the MainActivity File. Comments are added inside the code to understand the code in more detail.

MainActivity File:


Step 8: Update themes.xml

In the newer versions of Android Studio, the action bar is removed by default. To change that, navigate to app > res > values > themes.xml and update the base theme style

Before

<style name="Base.Theme.Demo" parent="Theme.Material3.DayNight.NoActionBar">

After

<style name="Base.Theme.Demo" parent="Theme.Material3.DayNight">

Click Here to get the full Project for SearchView with RecyclerView

Output:


Comment

Explore