Displaying bitmap image in imageview by simple adapter

前端 未结 3 715
情书的邮戳
情书的邮戳 2021-01-03 08:25

I am getting image from an url. I am using imageview in listview. I want to add the list of bitmap images into the each row of the list item. I used SimpleAdapter but the im

3条回答
  •  清歌不尽
    2021-01-03 09:11

    The best way to do it is to create a class that extends BaseAdapter and then instanciate an async task for every image (on post execute set the bitmap to the correpondent imageView). Here's a simple function to download an image from web:

    private Bitmap loadImageFromNetwork(String url) throws MalformedURLException, IOException {
        HttpURLConnection conn = (HttpURLConnection) (new URL(url)).openConnection();
        conn.connect();
        return BitmapFactory.decodeStream(new FlushedInputStream(conn.getInputStream()));
    }
    

提交回复
热议问题