user3578548
user3578548

Reputation: 25

how to get a result of String[] for position

i am using Universal Image Loader and get data from url. but i dont know how to get a result of String[] for position.

my code as follow. it show the an mistake"The value of the local variable IMAGES is not used"

public View getView(final int position, View convertView, ViewGroup parent) {
        View view = convertView;
        final ViewHolder holder;
        if (convertView == null) {
            view = getActivity().getLayoutInflater().inflate(R.layout.fragment_monster_list_item, parent, false);
            holder = new ViewHolder();
            holder.text = (TextView) view.findViewById(R.id.text);
            holder.image = (ImageView) view.findViewById(R.id.image);
            view.setTag(holder);
        } else {
            holder = (ViewHolder) view.getTag();
        }

        holder.text.setText("this is number "+ (position+1)+"photo" );

        imageLoader.displayImage(IMAGES[position], holder.image, options, animateFirstListener);

        return view;
    }

class showTask 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);
                    categoryList.add(monstersname);
                    Monsters_image.add(monstersimage);
                }
            }
            urlConn.disconnect();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    @Override
    protected void onPostExecute(Void result) {
        super.onPostExecute(result);
        String[] IMAGES = Monsters_image.toArray(new String[Monsters_image.size()]);
    }

}

Upvotes: 0

Views: 149

Answers (1)

MickG
MickG

Reputation: 3276

Don't worry about that warning, I would say. It's only telling you IMAGES is never mentioned except where it is declared. I guess your code is not yet complete, otherwise you would not have an unused variable. I bet if you go on writing your code, there will be some point where you will use that variable, and make the warning disappear.

I do not actually understand your code, as try and catch are constructs I have never used or been taught to use, but finishing the program before minding warnings is a good idea. By the way, once you get to the point of using that String[] IMAGES somewhere, save the document, because otherwise the editor might remember the "mistake" and keep warning you.

Upvotes: 3

Related Questions