This article explains the Universal Image Loader. The Universal Image Loader allows you to set various image view options. You can load the image from a URL at runtime using this. The advantage of using this is that you need not store all the images you want to use in your project (in drawable). This saves memory. In large projects where memory management is crucial, using Universal Image Loader is a good idea.

Step 1:

You will need to include "universal-image-loader-1.7.0.jar" from the "library" zip, provided above, as a library in your project. Copy the jar file provided to the clipboard and paste it on the "libs" in your Eclipse project.

This jar contains the main functionalities that we will be using.

Step 2:

First we will make an application class that will set the basic configurations.

Right-click on your package name then select "New" -> "Class". Name it "App" and add the following code to it:

Open the "activity_main" layout file and add the following code to it:

<ScrollViewxmlns:android="http://schemas.android.com/apk/res/android"

android:layout_width="fill_parent"

android:layout_height="fill_parent" >

<LinearLayout

android:layout_width="fill_parent"

android:layout_height="fill_parent"

android:orientation="vertical" >

<TextView

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:gravity="center"

android:paddingBottom="10dip"

android:paddingTop="20dip"

android:text="Welcome to Universal Image Loader...."

android:textSize="24sp" />

<Button

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:layout_margin="10dip"

android:onClick="listFunc"

android:text="Click here" />

</LinearLayout>

</ScrollView>

Step 4:

Create a layout for displaying the list of images in a list view. Right-click on layout then select "New" -> "Other" -> "Android" -> "Android Layout XML file". Name this file as "image_listview_layout" and add the following code to it:

<ListViewxmlns:android="http://schemas.android.com/apk/res/android"

android:id="@android:id/list"

android:layout_width="fill_parent"

android:layout_height="fill_parent" />

Step 5:

Right-click on layout then select "New" -> "Other" -> "Android" -> "Android Layout XML file". Name this file as "image_list_layout" and add the following code to it:

"images" is a string array that contains the list of image URL's. First we have set the initial configurations of the image. "stub_image" is the image that will be displayed until the image from the URL is not loaded. In "getView()" we have set the content of list view. You will need to paste the images that you want to use as a stub_image and the image used in "showImageForEmptyUri()" in your drawable folder.

Step 9:

Create a class to provide a larger view to the image when selected by the user from the list.

Right-click on your package name then select "New" -> "Class". Name it "SeperateView" and add the following code to it: