這是代碼,圖像確實下載了,但問題是,我無法顯示,因爲沒有beeing能夠解決方法findViewByIdAndroid的 - 異步下載圖像,並將其顯示
public class ImageDownloader
extends AsyncTask<String, Integer, Bitmap> {
protected void onPreExecute(){
//Setup is done here
}
@Override
protected Bitmap doInBackground(String... params) {
//this where i get the image using HttpURLConnection
}
protected void onProgressUpdate(Integer... params){
//Update a progress bar here, or ignore it, it's up to you
}
protected void onPostExecute(Bitmap img){
//here is the problem with findViewById beeing undefined
ImageView image_view = (ImageView) findViewById(R.id.remote_image);
if(image_view!=null && img!=null){
image_view.setImageBitmap(img);
}
}
在我的主呢活動我叫裏面的OnCreate的ImageDownloader這樣的:
ImageDownloader download = new ImageDownloader();
download.execute("http://wanderingoak.net/bridge.png");
`
是'remote_image'圖像視圖的ID在你的** **當前佈局? –
明顯asynctask沒有這樣的方法...顯然你必須通過imageview引用或使你的asynctask實現內部非靜態類的類有這樣的方法...看起來像缺乏Java的基礎知識(不與android所有) – Selvin
是的,它是位於content_main.xml裏面的ImageView名稱 – Akis