要在活动中的onCreate显示AlertDialog - 机器人要在、机器人、活动中、onCreate

2023-09-04 06:12:11 作者:Infatuation(痴心)

在我的活动,我称之为MyDialog(自定义对话框)中的onCreate(),并处理其在活动DismissListener发现如果取消与否。如果取消了,我完成了活动,否则加载activty。在此装载时间,我想显示警报/进度对话框,让用户知道它的加载中,请稍候。但我无法看到的对话框。这是我怎么也得codeD:

In my activity, I call a MyDialog (custom dialog) in onCreate() and handle its DismissListener in Activity to find if its cancelled or not. If its cancelled, I finish the activity, else load the activty. During this loading time, I want to show a Alert/Progress dialog to let the user know that its loading, please wait. But am not able to see the dialog. This is how I have coded :

  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()也,但也没有成功,同样的结果。

Why am I not able to see any dialog in any way ? I tried calling them in LoadAfterAgree() also, but there also no success, same results.

任何帮助是非常AP preciated。

Any help is highly appreciated.

感谢

推荐答案

你执行你的长期业务UI线程。将它们移动到的AsyncTask的doInBackground方法。见这里的例子 。

you're performing your long operations in UI thread. Move them to the AsyncTask's doInBackground method. See the example here.