【问题标题】:Android: Setting Icon in a list ViewAndroid:在列表视图中设置图标
【发布时间】:2011-08-17 16:46:48
【问题描述】:

目前,我有几个 twitter 提要的 json 数据,我解析这些数据以填充我的列表。我有一个对象“图像”,其中包含我想在列表中设置为 ImageView 的用户图标的 url。我无法弄清楚如何获取 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);

    }

【问题讨论】:

标签: android json listview icons gson


【解决方案1】:

How to display image from URL on Android

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

【讨论】:

  • 嘿,我遇到的真正问题是如何将 url 获取到我的图像管理器并将其设置为“i”个不同的次数。我试过 map.put("image", c.getString("image"));但无法弄清楚如何为我的 imagemanager 函数赋予该值。这有意义吗?
  • 当您Log.i("IMAGE:", c.getString("image")); 时,您看到网址了吗?
  • 好。现在按照我告诉你的去做,在你实例化 imageview 的 getView() 中,因为你拥有所有的 url,所以对图像进行处理。执行urlList.get(position); 之类的操作,这样每个项目都有一个网址(因此每个项目一张图片)。你明白我的想法了吗?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-11-20
  • 1970-01-01
相关资源
最近更新 更多