1

I just want to ask, is that possible to load drawable from arraylist inside arrays.xml using Lazy Image Loader or Universal Image Loader?

First load arraylist of drawable

....

ArrayList<Integer> sample_list = new ArrayList<Integer>();

....

Resources resources = getResources();
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) {
           sample_list.add(res);
    }
}

Set drawable to imageview

imageView.setImageResource(sample_list.get(position));

Last time I used like above, but I want to use Lazy Image Loader or Universal Image loader

I dont use any url to load image

So is that possible?

If possible is there any sample?

Dave Newton
  • 158,873
  • 26
  • 254
  • 302
user3273595
  • 83
  • 1
  • 1
  • 10

1 Answers1

0

This method is not recommending for loading the images in drawable... You should use native method

Since u r using arraylist if u r saving the image name ids u can use like

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

(here this.R.drawable.image would be ur arraylist value.

NOTE:From: https://github.com/nostra13/Android-Universal-Image-Loader they are recommending to use native method if u want to show images from drawable

imageview.setImageResources(res id);
Tamilselvan Kalimuthu
  • 1,534
  • 1
  • 13
  • 28
  • But I want to set image from arraylist which contains a lot of drawable. At the moment I'm using CustomAdapter to display it, but that's eating a lot of memory ... So that's not possible? – user3273595 Feb 12 '14 at 03:34
  • u can use image uri. i updated my ans, what is the necessory to use imageloader for this? – Tamilselvan Kalimuthu Feb 12 '14 at 03:37
  • So I need to define all of my drawable from arraylist? Can I do like String imageUri = "drawable://" -- get the id from arraylist based on it's position -- ? – user3273595 Feb 12 '14 at 03:42
  • first tel me what is the need to show drawable images using imageloader? – Tamilselvan Kalimuthu Feb 12 '14 at 03:43
  • As I said before, I tried to display using ArrayAdapter, but loads so slow, even I have decode the drawable to Bitmap. I'm trying to display a lot of drawable, all of drawable only have resolution 96x96 pixels. I just trying to find another way – user3273595 Feb 12 '14 at 03:49
  • This is the reason why I'm trying to use Imageloader [stackoverflow- question](http://stackoverflow.com/questions/12598701/what-is-the-maximum-number-of-items-in-gridview) – user3273595 Feb 12 '14 at 03:55
  • Okay u can save the id's into the arraylist and use the imageURI to get the uri inside the adapter and load the image using imageloader. – Tamilselvan Kalimuthu Feb 12 '14 at 04:01
  • If possible, could you please give an example how to get the id based on the position? Please ... – user3273595 Feb 12 '14 at 04:03
  • I mean like get imageURI from the id that I saved inside arraylist – user3273595 Feb 12 '14 at 04:08
  • u r using imageView.setImageResource(sample_list.get(position)); inside adapter now, instead of that inside adapter u r going to set the imageUri and use that imageUri with imageloader , can u understand? – Tamilselvan Kalimuthu Feb 12 '14 at 04:12