Dedicated Server

Android RecyclerView search using adapter Filter method

The following is an overview of what we are about to learn in this tutorial

RecyclerView SearchView example
In this tutorial, we will be parsing a json array example into  a recyclerview as shown above and then use the filter feature in recyclerview adapter to perform search operations in the recyclerview list. The below json is the one that we are about to parse.





AndroidManifest.xml
app level build.gradle file
First of all, add the following changes in resource files

strings.xml
colors.xml
Now go to your "res" dirctory and right click on it, go to new>>Android Resource Directory and choose resource type as menu. Then click ok to create menu directory inside res folder. Now create another file menu_main.xml inside the menu directory that we just created.

menu_main.xml
Now make the following changes and additions to the layout files

activity_main.xml
The following layout provides the design for each item in a recyclerview

item_layout.xml
Our res folder will have the below directory structure
res folder directory structure

Now let us head over to some java code, first of all go ahead and create your model class like shown below
CarModel.java.java

Now create a recyclerview adapter for your recyclerview like shown below
DataAdapter.java
Now create a retrofit interface to define your network endpoint like shown below
RequestInterface.java
Since we are parsing json array example, we will need to fetch the results as a list of CarModel. So finally create MainActivity.java file with the network calls as shown below
Now the complete directory structure will be like
full directory structure

2 comments: