Android:在列表视图中设置图标

时间:2011-08-17 16:46:49

标签: android json listview icons gson

目前,我有几个Twitter提要的json数据,我解析它来填充我的列表。我有一个对象,“图像”,其中包含我想要在列表中设置为ImageView的用户图标的URL。我无法弄清楚如何获取网址并在Imageview中为每一行加载图片。这是代码:

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

    }

1 个答案:

答案 0 :(得分:0)

How to display image from URL on Android

看到这个问题。看起来对我很实用。在getView()方法中显示图像,填充列表并实例化子视图。