我怎么能使用setViewImage在SimpleAdapter? [英] How could I use setViewImage in SimpleAdapter?

查看:173
本文介绍了我怎么能使用setViewImage在SimpleAdapter?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要建立从网页中的图像列表视图。我也问过一个其他问题:<一href=\"http://stackoverflow.com/questions/13209748/android-listview-with-images-from-special-hashmap\">Android ListView控件与特殊的HashMap 图像。
但现在我试图延长SimpleAdapter。我使用HashMap把数据。然后,我用一个新的ImageAdapter

I will build a listview with images from the web. I've also asked an other question before: Android ListView with images from special hashmap. But now I tried to extend the SimpleAdapter. I use a hashmap to put the data. Then I use a new "ImageAdapter":

public class ImageAdapter extends SimpleAdapter {

         public ImageAdapter(Context context,
                    List<? extends Map<String, ?>> data, int resource, String[] from,
                    int[] to) {
                super(context, data, resource, from, to);
                // TODO Auto-generated constructor stub
            }

         @Override
            public void setViewImage(ImageView v, String value) {
                super.setViewImage(v, value);
                URL url;
                try {
                    url = new URL(value);
                    URLConnection conn = url.openConnection();
                    conn.connect();
                    InputStream is = conn.getInputStream();
                    Bitmap bm = BitmapFactory.decodeStream(is);
                    v.setImageBitmap(bm);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }

          }

我list.xml:

My list.xml:

[...]
<ImageView
            android:id="@+id/list_image"
            android:layout_width="50dip"
            android:layout_height="50dip" />
[...]

有没有错误 - 但ImageView的是空白/白!我怎么能填充数据定义的图像的ImageView的(如字符串/ URL):

There is no error - but the imageview is blank / white! How could I fill the imageview with the image defined in data (as String / URL):

ada = new ImageAdapter(getApplicationContext(), data, R.layout.list, new String[] {"imgurl", "title", "date", "ex", "id"}, new int[] {R.id.list_image, android.R.id.text1, android.R.id.text2, R.id.text3});

感谢您的帮助!我尝试了许多变化......但没有任何工程:(

Thanks for helping! I tried many variations...but nothing works :(

推荐答案

我建议你阅读本的教程。您将了解BaseAdapter,ViewHolder模式,正确的异步图像加载。

I recommend you to read this tutorial. You will learn about BaseAdapter, ViewHolder pattern and correct asynchronous image loading.

这篇关于我怎么能使用setViewImage在SimpleAdapter?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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