A优化添加图片

来源:互联网 发布:淘宝店招模板制作 编辑:程序博客网 时间:2024/04/27 18:24
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;}