机器人:通用图像装载机得到字符串数组绘制 [英] android: Universal Image Loader get drawable from string array
问题描述
主要是我发现像这样的网络
公共静态最终的String [] IMAGEURL =新的String [] {
http://sample.com/sample1.png
http://sample.com/sample1.png
};
所以加载图像时,我们只需要调用
imageloader.displayImage(IMAGEURL [位置],ImageView的,选项);
我的问题
我有字符串数组里面arrays.xml
<字符串数组名=样本>
<项目>与此搜索LT; /项目>
<项目> IMAGE2< /项目>
<项目>的Image3< /项目>
<项目>为image4< /项目>
< /字符串数组>
然后我想读样品字符串数组里面arrays.xml
....
ArrayList的<整数GT;名单=新的ArrayList<整数GT;();
....
最后的资源资源= getResources();
。最后弦乐的packageName = getApplication()getPackageName();
最终的String []演员= resources.getStringArray(R.array.sample);
对于(字符串加:演员){
INT RES = resources.getIdentifier(多余的,绘制的packageName);
如果(水库!= 0){
list.add(RES);
}
}
如何载入图像从ArrayList的?
这就像
imageloader.displayImage(list.get(位置),ImageView的,选项);
或
如何设置的String []从字符串数组中ARRAYS.XML?
我不想手动设置像这样
公共静态最终的String [] IMAGEURL =新的String [] {
绘制://R.drawable.image1
绘制://R.drawable.image2
...
};
有关绘制数组,你可以试试这个:
字符串imageUri =绘制://+ R.drawable.image;
而不是R.drawable.image只是通过阵列的位置。
示例:
声明的绘制数组:
公共静态最终诠释[] IMAGEURL =新INT [] {
R.drawable.image1,
R.drawable.image2,
...
};
Baseadapter现在里面getview()方法:
imageloader.displayImage(绘制://+ IMAGEURL(位置),ImageView的,选项);
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
...
};
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);
这篇关于机器人:通用图像装载机得到字符串数组绘制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!