A优化添加图片

移动开发 waitig 539℃ 百度已收录 0评论
private void dispalyImage(final String picUrl, final ImageView imageView) {
    AsyncTask<Void, Void, Bitmap> asyncTask = new AsyncTask<Void, Void, Bitmap>() {
        @Override
        protected Bitmap doInBackground(Void... voids) {
            try {
                URL url=new URL(picUrl);

                HttpURLConnection connection = (HttpURLConnection) url.openConnection();

                connection.setRequestMethod("GET");
                connection.setReadTimeout(5000);
                connection.setConnectTimeout(5000);
                int responseCode = connection.getResponseCode();
                while (responseCode==200){
                    InputStream inputStream = connection.getInputStream();
                    Bitmap bitmap= BitmapFactory.decodeStream(inputStream);
                    return bitmap;


                }

            } catch (Exception e) {
                e.printStackTrace();
            }

            return null;
        }

        @Override
        protected void onPostExecute(Bitmap bitmap) {
          imageView.setImageBitmap(bitmap);
        }
    };
    asyncTask.execute();

}

class ViewHolder{

    ImageView imageView;
    TextView text_title;
    TextView text_time;
}

本文由【waitig】发表在等英博客
本文固定链接:A优化添加图片
欢迎关注本站官方公众号,每日都有干货分享!
等英博客官方公众号
点赞 (0)分享 (0)