如何改变数组列表以字符串数组使用通用图像装载机? [英] How to change array list to string array for using Universal Image Loader?
问题描述
我的android的新手。我只是尝试学习如何使用通用图像装载机
。
我发现网址
图像的通用图像装载机
静态设置或preSET在的String []图片
。不过,我想对那些图像从网址
更改。因此,我与解析 XML完成
,并尝试从 XML Web服务
。
不过,我不知道如何改变数组列表字符串数组。有人可以教我吗?
的 XML Web服务
code如下:
类showCategoryTask扩展的AsyncTask<太虚,太虚,太虚> {
@覆盖
保护无效doInBackground(虚空...... PARAMS){
尝试{
网址URL =新的URL(http://garyhui86.er-webs.com/monstersxml.php);
HttpURLConnection的urlConn =
(HttpURLConnection类)url.openConnection();
如果(urlConn.getResponse code()== HttpURLConnection.HTTP_OK){
的DocumentBuilder建设者=的DocumentBuilderFactory
。.newInstance()newDocumentBuilder();
文献文件= builder.parse(urlConn.getInputStream());
节点列表节点列表= document.getElementsByTagName(信息);
的for(int i = 0; I< nodeList.getLength();我++){
的NamedNodeMap属性= nodeList.item(ⅰ).getAttributes();
字符串monstersname = attributes.getNamedItem(monsters_name)getNodeValue()。
字符串monstersimage = attributes.getNamedItem(monsters_image)getNodeValue()。
Log.i(TTT,monstersname);
Monsters_image.add(monstersimage);
}
}
urlConn.disconnect();
}赶上(例外五){
e.printStackTrace();
}
返回null;
}
}
将您的字符串的ArrayList
为字符串阵列
像
的String []海峡= list.toArray(新的String [则为list.size()]);
I am a Novice of android. I just try to learn how to use Universal Image Loader
.
I find that the url
of the images in Universal Image Loader
are set statically or preset in String[] IMAGES
. But I would like to change those image from URL
. So I am done with parsing the XML
and try to get those data from XML Web service
.
However, I don't know how to change array list to string array. Can someone teach me?
The xml web service
code as follow:
class showCategoryTask extends AsyncTask<Void, Void, Void> {
@Override
protected Void doInBackground(Void... params) {
try {
URL url = new URL("http://garyhui86.er-webs.com/monstersxml.php");
HttpURLConnection urlConn =
(HttpURLConnection)url.openConnection();
if (urlConn.getResponseCode() == HttpURLConnection.HTTP_OK) {
DocumentBuilder builder = DocumentBuilderFactory
.newInstance().newDocumentBuilder();
Document document = builder.parse(urlConn.getInputStream());
NodeList nodeList = document.getElementsByTagName("Info");
for (int i = 0; i < nodeList.getLength(); i++) {
NamedNodeMap attributes=nodeList.item(i).getAttributes();
String monstersname=attributes.getNamedItem("monsters_name").getNodeValue();
String monstersimage=attributes.getNamedItem("monsters_image").getNodeValue();
Log.i("ttt", monstersname);
Monsters_image.add(monstersimage);
}
}
urlConn.disconnect();
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
}
Convert your String ArrayList
to String Array
like
String[] str=list.toArray(new String[list.size()]);
这篇关于如何改变数组列表以字符串数组使用通用图像装载机?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!