Dedicated Server
Showing posts with label retrofit recyclerview. Show all posts
Showing posts with label retrofit recyclerview. Show all posts

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.

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

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.

Now make the following changes and additions to the layout files

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

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

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