android: Universal Image Loader get drawable from string array

user3273595

Mostly I found like this on Internet

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

So when loading image we just need to call

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

MY QUESTION

I have 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'm trying to read sample string array inside arrays.xml

....
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 LOAD IMAGES FROM ARRAYLIST?

It's like

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

OR

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

I don't want to set it manually like this

public static final String[] imageurl = new String[] {
    "drawable://" R.drawable.image1
    "drawable://" R.drawable.image2
    ...
};
Chirag Shah

for drawable array ,you can try this:

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

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

Example :

Declare your drawable array :

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

};

now inside getview() method of Baseadapter :

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

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Android universal image loader get picture

How to change array list to string array for using Universal Image Loader?

Converting an image from drawable to byte array in Android

android universal image loader not caching or saving image

Universal Image Loader, download image from FTP

kotlin - get image from image array in drawable folder

Android Universal image loader, stop retry

Android: Universal Image Loader and the blank space issue

android - galley with Picasso or Universal Image Loader

android universal image loader clear cache

android universal image loader out of memory error

android universal image loader for two listview in viewpager

Universal image loader recache from Internet

Drawable from String in Android

Loading images from url using Universal Image Loader gives nullpointer exception in Android

Universal Image Loader with PhotoView

Android: Universal Image Loader - Add new image to cache

How to show Video and image Thumbnail using Universal image loader in android?

Loading image from the internet inside a fragment with Universal Image Loader

how to get drawable from string?

Image not loading with universal image loader

Pre-downloading images with Android-Universal-Image-Loader

Android Universal Image Loader requests with same URL are being cancelled

Universal Image Loader portrait/ landscape issue Android Studio

Android Universal Image Loader store downloaded progress listview

what is the difference between Android-Universal-Image-Loader and ImageLoader

How to get the drawable image path in android?

android get Drawable image after picasso loaded

Combining CoverFlow and Universal Image Loader

TOP Ranking

HotTag

Archive