2 回答
TA贡献1846条经验 获得超7个赞
您可以执行一些操作,例如在构造函数中将图像视图传递到异步任务中。为此,首先修改您的异步任务,如下所示:
class AsyncForBitmap extends AsyncTask<String, Void, Bitmap> {
private final ImageView mImageView;
public AsyncForBitmap(ImageView imageView){
mImageView = imageView;
}
private Exception exception;
protected Bitmap doInBackground(String... urls) {
try {
URL url=new URL(urls[0]);
Bitmap bitmap = BitmapFactory.decodeStream((InputStream)url.getContent());
return bitmap;
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
protected void onPostExecute(Bitmap bitmap){
mImageView.setImageBitmap(bitmap);
}
}
然后,只需执行以下操作:
...
case XmlPullParser.START_TAG:
if (tagname != null && tagname.equals(iconsrc)){
iconsrcVALUE = parser.getAttributeValue(0);
new AsyncForBitmap(IV).execute(iconsrcVALUE);
}
break;
TA贡献1876条经验 获得超5个赞
试试这个代码
protected void onPostExecute(Bitmap bitmap) {
runOnUiThread(new Runnable() {
@Override
public void run() {
mImageView.setImageBitmap(bitmap);
}
});
}
添加回答
举报