How could I use setViewImage in SimpleAdapter?

Ask by : user1756209 November 04, 2012 13:15

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

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


My list.xml:

            android:layout_height="50dip" />

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[] {,,,});

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

View original question

Answer by : Dmytro DanylykNovember 04, 2012 13:15

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

View original answer