Dedicated Server

Loading images using picasso library in android

In this tutorial we are about to load image in recyclerview using picasso library as shown in the following gif
images loaded in recyclerview using picasso library

In this tutorial we will be parsing the following json array example into a recyclerview along with the images
You can check the json file here https://navneet7k.github.io/cars_list.json
Update internet permission in AndroidManifest.xml as shown below
Add the dependencies for cardview,design,retrofit,converter-gson and picasso in your app level build.gradle as shown below
Please make sure that you add the dependencies in app level build.gradle itself and not project level build.gradle like depicted below

build.gradle files


Create model class like shown below

CarItem.java
Create recyclerview adapter

DataAdapter.java
Here we have used

 Picasso.get().load(articles.get(i).getImage()).resize(500,500).into(viewHolder.car_img); 

to load the image into car_img using Picasso library. Also I have implemented a filter method in the above adapter class which you can use to integrate a search feature in the above recyclerview - you may check this tutorial to integrate search feature inside recyclerview.

create activity file

MainActivity.java
Since we have to parse a json array example, we have used List<CarItem> as response parameter type in retrofit callback methods as shown above. If we were parsing a json object example, we would have to set CarItem as response parameter type.

RequestInterface.java
Now create the resource files

activity_main.xml
item_layout.xml
colors.xml
strings.xml

No comments:

Post a Comment