android:通用图像加载器可从字符串数组中绘制 [英] android: Universal Image Loader get drawable from string array
本文介绍了android:通用图像加载器可从字符串数组中绘制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
主要是我在网上找到的这个
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);
我的问题
我在arrays.xml中有字符串数组
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>
然后我试图读取 arrays.xml 中的示例字符串数组
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);
}
}
如何从数组中加载图像?
就像
imageloader.displayImage(list.get(position), imageView, options);
或
如何从 ARRAYS.XML 中的字符串数组设置 STRING[]?
我不想像这样手动设置
public static final String[] imageurl = new String[] {
"drawable://" R.drawable.image1
"drawable://" R.drawable.image2
...
};
推荐答案
对于 drawable 数组,你可以试试这个:
for drawable array ,you can try this:
String imageUri = "drawable://" + R.drawable.image;
而不是 R.drawable.image 只需传递您的数组位置.
instead of R.drawable.image just pass your array position.
示例:
声明你的可绘制数组:
public static final int[] imageurl = new int[] {
R.drawable.image1,
R.drawable.image2,
...
};
现在在 Baseadapter 的 getview() 方法中:
now inside getview() method of Baseadapter :
imageloader.displayImage("drawable://"+imageurl(position), imageView, options);
这篇关于android:通用图像加载器可从字符串数组中绘制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文