Home Tutorials Training Consulting Products Books Company Donate Contact us









Online training

Events

Quick links

Share

(c) 2009, 2017 vogella GmbH Version 0.3, 25.10.2017

This tutorial describes how to download efficiently images using Google Glide.

1. Google Glide for image processing

Every application needs to download and manage images.

Google Glide makes this easy.

To use Glide add the following dependency to your app/build.gradle file.

dependencies {
    compile 'com.github.bumptech.glide:glide:3.8.0'
    compile 'com.android.support:support-v4:25.3.1'
    // more stuff
}

The usage is simple.

// simple usage
Glide.with(myListFragment)
    .load("url").into(imageView)

// with placeholder
    Glide.with(myListFragment)
    .load("url").placeholder(R.drawable.loading_spinner).into(imageView)

2. Exercise - Using Glide to download images into your RecyclerView

Use Glide to download images into your RecyclerView adapter. As a first step add the Glide dependencies to your Gradle build file.

dependencies {
    compile 'com.github.bumptech.glide:glide:3.8.0'
    compile 'com.android.support:support-v4:25.3.1'
    // more stuff
}

The Internet provides free example picture services for testing, for example:

Adjust your adapter implementation in your Recyclerview.

   @Override
    public void onBindViewHolder(final ViewHolder holder, final int position) {
        final RssItem rssItem = rssItems.get(position);
        holder.txtHeader.setText(rssItem.getTitle());
        holder.txtFooter.setText(rssItem.getLink());
        holder.mainLayout.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                myListFragment.updateDetail(rssItem.getLink());
            }
        });
        // to download some random data
        Random r = new Random();
        int i = r.nextInt(10);
        Glide.with(myListFragment).load("http://lorempixel.com/400/200/sports/"+i+"/").
                into(holder.imageView);
    }
Glide output result in RecyclerView

4. vogella training and consulting support

Copyright © 2012-2018 vogella GmbH. Free use of the software examples is granted under the terms of the Eclipse Public License 2.0. This tutorial is published under the Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Germany license.