0

如何在列表视图中显示来自 JSON 的图像和字符串文本?

// new HashMap
HashMap<String, String> hashMap = new HashMap<String, String>();

String imageName = c.getString("avater");
URL url1 = new URL(imageName);
HttpURLConnection connection = (HttpURLConnection) url1.openConnection();

InputStream is = connection.getInputStream();
Bitmap img = BitmapFactory.decodeStream(is); 

//updating listview with the parsed items
ListAdapter adapter = new SimpleAdapter(
    Inboxtest.this,
    entryList,
    R.layout.inboxlist,
    new String[] { TAG_QUERY, TAG_RESULT, timesent, icon },
    new int[] { R.id.textView1, R.id.textView3, R.id.textView2, R.id.textView4 }
);

setListAdapter(adapter);

我需要将图像放在此列表中。

4

2 回答 2

0

您将需要通过 xml 创建一个自定义 listview_row 布局文件。并通过创建一个将解析的 JSON 数据与图像一起绑定到列表的适配器来扩充该自定义行。几天前我回答了一个非常相似的问题,所以我不会在这里重新发布该代码,但我会将您链接到该问题。另外,我发布了一个博客链接,介绍如何创建包含文本、图像和自定义适配器的自定义列表。希望这对人有所帮助。

上一个 SO 问题 https://stackoverflow.com/a/13186855/949266

在这里找到我的博客文章 http://jadebyfield.blogspot.com/

于 2012-11-19T21:40:20.893 回答
0

尝试使用ImageLoader的延迟加载在 ListView 中显示图像。通过这种方式,您的 UI 将保持响应。

使用包装器来存储图像名称及其 URL。把它放到一个数组列表中,然后在 ListAdapter 中使用这个数组列表。

为具有 textview 和 imageview 的 ListView 创建一行(在 xml 中)。在自定义 ListAdapter 的 getView 中设置图像名称和图像。

试试看。如果你卡住了,我会分享代码。

快乐编码!

于 2012-11-19T21:14:33.213 回答