How to change array list to string array for using Universal Image Loader?

不羁的心 提交于 2019-12-26 01:54:06

问题


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

回答1:


Convert your String ArrayList to String Array like

 String[] str=list.toArray(new String[list.size()]);



回答2:


Try this way

ArrayList<String> list = new ArrayList<String>();
        list.add("item1");
        list.add("item2");
        String[] Arr = new String[list.size()];
        Arr = list.toArray(Arr);



回答3:


String[] array = new String[list.size()];
int i = 0;
for (String string : list) {
    array[i++] = string;
}


来源:https://stackoverflow.com/questions/23841213/how-to-change-array-list-to-string-array-for-using-universal-image-loader

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!