Android: Universal Image Loader gets the ability to draw from a string array

I basically found this on the Internet

public static final String[] imageurl = new String[] {
    "http://sample.com/sample1.png",
    "http://sample.com/sample1.png"
};

Therefore, when uploading an image, we just need to call

imageloader.displayImage(imageurl[position], imageView, options);

MY QUESTION

I have a string array inside arrays.xml

<string-array name="sample" >
    <item>image1</item>
    <item>image2</item>
    <item>image3</item>
    <item>image4</item>
</string-array>

Then I try to read an array of strings in an arrays.xml array

....
ArrayList<Integer> list = new ArrayList<Integer>();
....

final Resources resources = getResources();
final String packageName = getApplication().getPackageName();
final String[] extras = resources.getStringArray(R.array.sample);
for (String extra : extras) {
    int res = resources.getIdentifier(extra, "drawable", packageName);
    if (res != 0) {
        list.add(res);
    }
}

HOW TO DOWNLOAD IMAGES FROM ARRAYLIST?

Like it

imageloader.displayImage(list.get(position), imageView, options);

OR

HOW TO INSTALL LINE [] FROM STRING ARRAY INSIDE ARRAYS.XML?

I do not want to install it manually like this

public static final String[] imageurl = new String[] {
    "drawable://" R.drawable.image1
    "drawable://" R.drawable.image2
    ...
};
+3
source share
1 answer

for a drawn array, you can try the following:

String imageUri = "drawable://" + R.drawable.image;

instead of R.drawable.image just pass the position of your array.

Example:

Declare your drawable array:

public static final int[] imageurl = new int[] {
 R.drawable.image1,
 R.drawable.image2,
...

};

now inside the getview () method of the Baseadapter:

imageloader.displayImage("drawable://"+imageurl(position), imageView, options);
+28

All Articles