gpt4 book ai didi

java - 带有来自特殊 HashMap 的图像的 Android ListView

转载 作者:行者123 更新时间:2023-11-30 03:56:51 24 4
gpt4 key购买 nike

我尝试处理 HashMap 以显示带有图像的 ListView 。我在这里搜索答案:How to display Images in ListView android .但它不起作用...

我的代码是:

for (int i = 0; i < nodes.getLength(); i++) {
Element e = (Element)nodes.item(i);
Map<String, Object> datum = new HashMap<String, Object>(2);
String img_url = getValue(e, "pic");
URL url = null;
try {
url = new URL(img_url);
} catch (MalformedURLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
Bitmap bmp = null;
try {
bmp=BitmapFactory.decodeStream(url.openConnection().getInputStream());
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}

datum.put("imgurl", bmp);
datum.put("title", getValue(e, "title"));
datum.put("date", getValue(e, "description"));
datum.put("ex", "Autor: "+getValue(e, "creator")+" · Datum: "+getValue(e, "pubDate"));
datum.put("id", getValue(e, "id"));

data.add(datum);
}


final ListView lv = (ListView)findViewById(R.id.listView1);
ada = new SimpleAdapter(getApplicationContext(), data, R.layout.vlistimage, new String[] {"imgurl", "title", "date", "ex", "id"}, new int[] {R.id.list_image, android.R.id.text1, android.R.id.text2, R.id.text3});
lv.setAdapter(ada);

感谢提示/帮助!

最佳答案

这是一个非常常见的问题,您可以通过 google 搜索示例。我可以肯定地告诉您,将图像存储在内存中是错误的,因为您可能会遇到OutOfMemoryException

要了解如何使用图像和缓存,请访问 Displaying Bitmaps Efficiently

关于java - 带有来自特殊 HashMap 的图像的 Android ListView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13209748/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com