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;
}
}