我有一個ProgressDialog
成立,但我不CA清除它!它只是繼續加載消息,並不會結束。我覺得我做的是正確的,設立展會消息onPreExecute
和dismiss
成onPostExecute
但一些如何,它只是不工作ProgressDialog辭退不工作
繼承人我的代碼:
public class MainActivity extends Activity {
//String[] imgUrls = {getString(R.string.uncc_main_thumb),getString(R.string.football_main_thumb,getString(R.string.ifest_main_thumb),getString(R.string.commencement_main_thumb))};
String[] imgUrls={"http://farm5.staticflickr.com/4113/4843614620_c541de5a5c_m.jpg",
"http://farm8.staticflickr.com/7265/8151547298_85e60e7368_m.jpg",
"http://farm9.staticflickr.com/8054/8414075899_e87a74407b_m.jpg",
"http://farm9.staticflickr.com/8210/8277674769_7d1245dbf1_m.jpg"};
ProgressDialog progressDialog;
ImageView iv1,iv2,iv3,iv4;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
iv1 =(ImageView) findViewById(R.id.imageView1);
iv2 =(ImageView) findViewById(R.id.imageView2);
iv3 =(ImageView) findViewById(R.id.imageView3);
iv4 =(ImageView) findViewById(R.id.imageView4);
for (String imgUrl : imgUrls) {
new DownLoadImages().execute(imgUrl);
}
}
private class DownLoadImages extends
AsyncTask<String, Void, Bitmap> {
@Override
protected Bitmap doInBackground(String... params) {
String imgUrl = params[0];
Bitmap image = null;
try {
URL url = new URL(imgUrl);
image = BitmapFactory.decodeStream(url.openStream());
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return image;
}
@Override
protected void onPreExecute() {
super.onPreExecute();
// show the loading message while downloading the image
ProgressDialog.show(MainActivity.this, null, "Loading");
}
@Override
protected void onPostExecute(Bitmap result) {
if (result == null) {
result = ((BitmapDrawable) getResources().getDrawable(
R.drawable.not_found)).getBitmap();
}
//ImageView imageViewToBeAdded = new ImageView(getBaseContext());
// imageViewToBeAdded.setLayoutParams(new LayoutParams(
// LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
// imageViewToBeAdded.setPadding(5, 5, 5, 5);
iv1.setImageBitmap(result);
progressDialog.dismiss();
}
}
}
喔謝謝!它現在的工作 – Samson
將此標記爲正確答案然後 – Divers
@Samson真的嗎?這怎麼可能?你有4個不同的ProgressDialog,你只是在你的循環的每一次迭代覆蓋引用 – Blackbelt