开发者

displaying a dialog in onCreate()

I may need to display a dialog box, depending upon a certain condition. This condition will have to be resolved before the application can continue. Basically, I need to "pause" the execution of my program until this dialog box has been destroyed. I have tried a bunch of different methods but I am running into a problem where the application continues to execute. Currently, the showDialog is in the onCreate() method of my main activity.

Any suggestions would be grea开发者_开发技巧tly appreciated.


If you want to run code only after a button has been pressed, you should use an `onClickListener':

See: http://developer.android.com/reference/android/app/AlertDialog.html#setButton(int, java.lang.CharSequence, android.content.DialogInterface.OnClickListener)

AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle(R.string.first_run_version_title)
    .setNeutralButton(R.string.ok_menu_button, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int id) {
            // code to run here
        }
    });
AlertDialog alert = builder.create();
alert.show(); // <-- Forgot this in the original post
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜