0
我有UI組件,其中我有包含ImageViews的表,現在我想從URL設置圖像。Android:從異步類更新UI組件
現在,當我嘗試異步調用圖像設置爲UI的其他類時,它給了我一個錯誤,即只能通過UI線程更新UI。我想加載UI並在圖像可用時加載圖像。
這裏是我的代碼:
Calling function...
new AsyncImageLoader(context,imgviewArray).execute();
// Called class..
@Override
protected Void doInBackground(Void... urls) {
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
int i = 0;
try{
db=new MyDB(mainact_instance);
System.out.println("Inside doInBackground");
if(isNetworkAvailable())
{
System.out.println("Network connected");
System.out.println("Fetching from network-Images");
Movie[] movies = db.selectRecords();
for(Movie mv : movies)
{
try {
URL url = new URL(IMAGE_URL+mv.getId()+".jpg");
Bitmap bmp = BitmapFactory.decodeStream(url.openConnection().getInputStream());
images[i].setImageBitmap(bmp);
i++;
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
else{
System.out.println("Network not connected..fetching max id row");
}
}catch(Exception ex){ex.printStackTrace();
}
return null;
//db.close();
}
請告訴我我怎麼能做到這一點?
謝謝它的作品... –