Lesson Weekend

The text in our custom list adapter is working just right, but we haven't updated the source for our ImageView yet. Let's do that now.

We will use another library by Square called Picasso which will make this task a piece of cake. Picasso simplifies the task of loading images into an Android application by offering automatic memory and disk caching, and other features.

We'll begin by adding it to our dependencies:

build.gradle (Module: app)
dependencies {
   ...
    compile 'com.squareup.picasso:picasso:2.5.2'
}

Now let's update the src for our list item ImageView. To attach the string imageUrl to the src, simply add the following to the bindRestaurants() method in our RestaurantListAdapter:

RestaurantListAdapter.java
public void bindRestaurant(Restaurant restaurant) {
            Picasso.with(mContext).load(restaurant.getImageUrl()).into(mRestaurantImageView);
            ...
        }

This line of code instructs the application to allow Picasso to handle the image loading. Now, if we run our application, we should see images next to each restaurant's details!


Example GitHub Repo for MyRestaurants