0

Currently, I have json data of several twitter feeds that I parse to fill my list. I have an object, "image" that contains the url of the users icon that I want to set as the ImageView to in the list. I am having trouble trying to figure out how I can take the url and load the image in the Imageview for each row. Here is the code:

public void getTweets(String selection) {
        String formatedcat = selection.toLowerCase();
        ArrayList<HashMap<String, String>> mylist = new ArrayList<HashMap<String, String>>();
        JSONObject json = JSONfunctions
                .getJSONfromURL("http://example.com/tweet.php");

        try {

            JSONArray category = json.getJSONArray(formatedcat);
            for (int i = 0; i < category.length(); i++) {
                HashMap<String, String> map = new HashMap<String, String>();
                JSONObject c = category.getJSONObject(i);

                map.put("id", String.valueOf(i));

                map.put("name",
                        c.getString("fullName") + "\n(#" + c.getString("name")
                                + ") ");
                map.put("text",
                        c.getString("text") + "\n - "
                                + c.getString("timestamp"));
                mylist.add(map);


            }
        } catch (JSONException e) {
            Log.e("log_tag", "Error parsing data " + e.toString());
        }

        ListAdapter adapter = new SimpleAdapter(this, mylist, R.layout.list,

                new String[] { "name", "text"}, new int[] { R.id.item_title,
                        R.id.item_subtitle});

        setListAdapter(adapter);



        final ListView lv = getListView();
        lv.setTextFilterEnabled(true);

    }
Nick
  • 9,285
  • 33
  • 104
  • 147

1 Answers1

0

How to display image from URL on Android

See this question. Look very practical to me. Do that showing of the image in the getView() method where you populate the list and instantiate the child views.

Community
  • 1
  • 1
Nikola Despotoski
  • 49,966
  • 15
  • 119
  • 148
  • Hey, The real issue I've been having is how to get the url to my image manager and set it "i" number of different times. I tried map.put("image", c.getString("image")); but can't figure out how to that value to my imagemanager function. Does this make sense? – Nick Aug 17 '11 at 17:21
  • When you `Log.i("IMAGE:", c.getString("image"));` do you see the url? – Nikola Despotoski Aug 17 '11 at 17:36
  • 1
    Good. Now do as I told you, in getView() where you instantiate the imageview do the thing with the image since you have all the urls. do something like `urlList.get(position);` so you have one url per item (thus one picture per item). You got my idea? – Nikola Despotoski Aug 17 '11 at 17:47