Android的ListView控件与特殊的HashMap图片 [英] Android ListView with images from special hashmap

查看:135
本文介绍了Android的ListView控件与特殊的HashMap图片的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图处理一个HashMap以显示与图像列表视图。我搜索喜欢这里的答案:如何显示的ListView android的。但它不工作...

I try to handle a hashmap to show a listview with images. I search for an answer like here: How to display Images in ListView android. But it doesn't work...

我的code是:

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

感谢您的提示/帮助!

推荐答案

这是很常见的问题,你可以谷歌的例子。我可以告诉你肯定它的错误以您的图像存储在内存中,你可以得到的 OutOfMemoryException异常

This is very common question and you could google example. What I can tell you for sure it is WRONG to store your images in memory, as you can get OutOfMemoryException.

要了解如何使用图像和高速缓存访​​问显示位图有效地

To learn how to work with images and cache visit Displaying Bitmaps Efficiently

这篇关于Android的ListView控件与特殊的HashMap图片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆