Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

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;
    }
}
share|improve this question
    
i am not sure that is work or not. because that was no image show in the apps. so i want to try to know the data of IMAGES . TextView webContent = (TextView)root.findViewById(R.id.textView1); webContent.setText(IMAGES); and there was an error . The method setText(CharSequence) in the type TextView is not applicable for the arguments (String[]) –  user3578548 May 24 at 5:41

3 Answers 3

up vote 2 down vote accepted

Convert your String ArrayList to String Array like

 String[] str=list.toArray(new String[list.size()]);
share|improve this answer
    
is it 「public static final String[] IMAGES = new String[] { urllink }; 」change into 「String[] IMAGES =Monsters_image.toArray(new String[Monsters_image.size()]);」 –  user3578548 May 24 at 4:56
    
@user3578548 do want to convert your Monsters_image arraylist? then it's right. –  Manish May 24 at 4:59
String[] array = new String[list.size()];
int i = 0;
for (String string : list) {
    array[i++] = string;
}
share|improve this answer
    
Please consider explaining your code when you answer a question with a code sample so that someone can learn from your example rather than simply copy it. Thx. –  dcc May 24 at 6:11

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);
share|improve this answer
    
is it 「public static final String[] IMAGES = new String[] { urllink }; 」change into 「String[] IMAGES = new String[Monsters_image.size()]; Arr = Monsters_image.toArray(IMAGES );」 –  user3578548 May 24 at 4:59

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.