在我的活動中,我調用了onCreate()中的MyDialog(自定義對話框),並在Activity中處理其DismissListener以查找它是否被取消。如果它被取消,我完成活動,否則加載活動。在此加載期間,我想顯示一個警報/進度對話框讓用戶知道它的加載,請稍候。但我無法看到對話框。這是我編碼的方式:想在Activity的onCreate中顯示AlertDialog - android
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ld = new AgreeDialog(this);
ld.setOnDismissListener(new OnDismissListener() {
@Override
public void onDismiss(DialogInterface dialog) {
if (ld.isCancelled)
MyActivity.this.finish();
else {
//ProgressDialog pd = CreateLoadingDialog();
//pd.show();
//Log.i(TAG, "Before Load Is PD showing - " + pd.isShowing()); // Shows true
/*
AlertDialog.Builder adb = new AlertDialog.Builder(StartUltimate.this);
adb.setTitle("Loading...");
adb.setCancelable(false);
AlertDialog ad = adb.create();
ad.show();
*/
MyActivity.this.showDialog(0);
LoadAfteAgree(); // This takes time sonetimes, so want a dialog while this is working
MyActivity.this.removeDialog(0);
//ad.dismiss();
// pd.dismiss();
//Log.i(TAG, "After Load Is PD showing - " + ad.isShowing()); // Shows false
}
}
});
@Override
protected Dialog onCreateDialog(int id) {
switch(id) {
case 0:
loadingDlg = new ProgressDialog(this);
loadingDlg.setMessage("Loading...");
loadingDlg.setCancelable(false);
loadingDlg.setIcon(R.drawable.icon);
return loadingDlg;
}
return null;
}
爲什麼我無法以任何方式看到任何對話?我也嘗試在LoadAfterAgree()中調用它們,但也沒有成功,結果相同。
任何幫助,高度讚賞。
謝謝
如果看不到任何對話框,請嘗試在「onStart()」方法中顯示它。 – 2011-04-22 13:45:00