将这个类写在listviev对应的activit中
private class asyncIma extends AsyncTask<URL,Integer,String>
{
Bitmap bitmapTemp21;
ImageView des;
public asyncIma(ImageView imageView)
{
des=imageView;
}
@Override
protected String doInBackground(URL... params) {
try
{
URL url = new URL("http://juheimg.oss-cn-hangzhou.aliyuncs.com/toh/200905/17/EC23523763.jpg");
InputStream is = url.openStream();
bitmapTemp21 = BitmapFactory.decodeStream(is);
}catch (Exception e)
{}
return null;
}
@Override
protected void onPostExecute(String s) {
try
{
des.setImageBitmap((Bitmap) bitmapTemp21);
}catch (Exception e)
{}
}
};
当想直接把listview对应的图片的网址直接放到适配器中可以如下配置适配器
simpleAdapter.setViewBinder(new SimpleAdapter.ViewBinder() {
@Override
public boolean setViewValue(View view, Object data, String textRepresentation) {
if (view instanceof ImageView && data instanceof String) {
final ImageView iv = (ImageView) view;
asyncIma m=new asyncIma(iv);
m.execute();
return true;
} else {
return false;
}
}
});
其他操作和以往一样