new MyAsyncTask()
.execute("http://pic.baike.soso.com/p/20120716/bki-20120716095331-640956396.jpg");
class MyAsyncTask extends AsyncTask<String, Void, Bitmap> {
@Override
protected void onPreExecute() {
// TODO 自动生成的方法存根
super.onPreExecute();
dialog.show();
}
@Override
protected Bitmap doInBackground(String... params) {
Bitmap bitmap = null;
HttpClient httpClient = new DefaultHttpClient();
HttpGet httpPost = new HttpGet(params[0]);
try {
HttpResponse respon = httpClient.execute(httpPost);
if (respon.getStatusLine().getStatusCode() == 200) {
HttpEntity entity = respon.getEntity();
byte[] data = EntityUtils.toByteArray(entity);
bitmap = BitmapFactory
.decodeByteArray(data, 0, data.length);
}
else {
}
} catch (Exception e) {
e.printStackTrace();
}
return bitmap;
}
@Override
protected void onPostExecute(Bitmap result) {
// TODO 自动生成的方法存根
super.onPostExecute(result);
imageView.setImageBitmap(result);
dialog.dismiss();
}
}