-1

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;
    }
}
user3578548
  • 25
  • 1
  • 7
  • 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 '14 at 05:41

3 Answers3

3

Convert your String ArrayList to String Array like

 String[] str=list.toArray(new String[list.size()]);
M D
  • 47,665
  • 9
  • 93
  • 114
  • is it 「public static final String[] IMAGES = new String[] { http://urllink }; 」change into 「String[] IMAGES =Monsters_image.toArray(new String[Monsters_image.size()]);」 – user3578548 May 24 '14 at 04:56
  • @user3578548 do want to convert your `Monsters_image` arraylist? then it's right. – M D May 24 '14 at 04:59
0

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);
Biraj Zalavadia
  • 28,348
  • 10
  • 61
  • 77
  • 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 '14 at 04:59
0
String[] array = new String[list.size()];
int i = 0;
for (String string : list) {
    array[i++] = string;
}
newx
  • 1
  • 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. – davidcondrey May 24 '14 at 06:11