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

发布于 2024-11-30 02:48:01 字数 1626 浏览 3 评论 0原文

目前,我有几个 twitter feed 的 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);

    }

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

    }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

绝不放开 2024-12-07 02:48:01

如何在 Android 上显示来自 URL 的图像

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

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文