In this tutorial, we will take a look into how to use Picasso library in android. Picasso is open source and one of the widely used image downloader library in Android. It is created and maintained by Square.
Popular Android image library for android.It simplifies the process of displaying images from all locations like External(URL) , internal(URI), file. In many cases only a few lines of code is required to implement this neat library.It shines displaying remote images.
The library handles every the process, from the initial HTTP request to the caching of the image.
Other alternatives instead of Picasso-
Universal Image Loader.
How to use Picasso library in Eclipse –
Download the Picasso JAR file, If you haven’t done it already. If you are using eclipse as your development IDE, then just copy the downloaded picasso-2.4.0.jar file into your application lib folder.
How to use Picasso library in Android Studio-
Loading Remote Image in ImageView –
We are done with configuration, let us see how to use this library to download images from remote server and display in ImageView. I assume you have your activity layout file already with ImageView declared on it.
To download image from server we need Internet permission so we have to add internet permission in our AndroidManifest.xml file
Picasso supports both download and error placeholders as optional features.In the above code snippet, we have just downloaded the image and displayed on ImageView. But that is not enough always. For any real time application, you must think of all possible cases. Now we need an placeholder and error fallback for our ImageView. Placeholder image will be shown before the image is loaded. Error fallback will be shown if, there is an error while downloading image. However both fallback and placeholder are optional.