Android 单击AlertDialog后如何转到下一页

Android 单击AlertDialog后如何转到下一页,android,Android,我正在使用我的应用程序,这是代码 单击AlertDialog中的“确定”按钮后,请帮助我进入其他页面“起始页” public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); new CountDownTimer(20000, 1000) {

我正在使用我的应用程序,这是代码

单击AlertDialog中的“确定”按钮后,请帮助我进入其他页面“起始页”

public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        new CountDownTimer(20000, 1000) {
            TextView tv = (TextView) findViewById(R.id.textView1);
             public void onTick(long millisUntilEnd) {
                 tv.setText(String.valueOf(millisUntilEnd / 1000));
             }

             public void onFinish() {
                 AlertDialog alertDialog1 = new AlertDialog.Builder(
                            MainActivity.this).create();
                // alertDialog1.setTitle("GAMEOVER");

                    // Setting Dialog Message
                    alertDialog1.setMessage("Time's Up!");

                    // Setting Icon to Dialog

                    // Setting OK Button
                    alertDialog1.setButton("OK", new DialogInterface.OnClickListener() {

                        public void onClick(DialogInterface dialog, int which) {

                            // Write your code here to execute after dialog
                            // closed
                           // Toast.makeText(getApplicationContext(),
                                    //"You clicked on OK", Toast.LENGTH_SHORT).show();
                        }
                    });

                    // Showing Alert Message
                    alertDialog1.show();

                 tv.setText("Game Over");
             }
            }.start();

谢谢。

在这里编写代码,转到其他页面

         alertDialog1.setButton("OK", new DialogInterface.OnClickListener() {

                                public void onClick(DialogInterface dialog, int which) {
        alertDialog1.dismiss();
    //then write code other page via intent
 Intent intent= new Intent(currentClassName.this ,otherClassName.class);
startActivity(intent);
                                }
                            });

在此处编写代码,转到其他页面

         alertDialog1.setButton("OK", new DialogInterface.OnClickListener() {

                                public void onClick(DialogInterface dialog, int which) {
        alertDialog1.dismiss();
    //then write code other page via intent
 Intent intent= new Intent(currentClassName.this ,otherClassName.class);
startActivity(intent);
                                }
                            });
试试这个:-

AlertDialog.Builder ab = new AlertDialog.Builder(context);
        ab.setMessage(msg);
        ab.setPositiveButton("OK", new OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {

                Intent in=new Intent(context, ExportActivity.class);
                            context.startActivity(in);
            }
        });
        ab.create().show();
如果您正在另一个类中编写警报消息,这里的上下文是您的活动上下文。如果警报消息在同一类中,则可以传递“this”来代替上下文

对于同一类替换

Intent in=new Intent(context, ExportActivity.class);
        context.startActivity(in);
由此

Intent in=new Intent(CurrentActivity.this, ExportActivity.class);
            startActivity(in);
这里的ExportActivity就是您想去的活动。 如果这对您有帮助,请告诉我。

试试这个:-

AlertDialog.Builder ab = new AlertDialog.Builder(context);
        ab.setMessage(msg);
        ab.setPositiveButton("OK", new OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {

                Intent in=new Intent(context, ExportActivity.class);
                            context.startActivity(in);
            }
        });
        ab.create().show();
如果您正在另一个类中编写警报消息,这里的上下文是您的活动上下文。如果警报消息在同一类中,则可以传递“this”来代替上下文

对于同一类替换

Intent in=new Intent(context, ExportActivity.class);
        context.startActivity(in);
由此

Intent in=new Intent(CurrentActivity.this, ExportActivity.class);
            startActivity(in);
这里的ExportActivity就是您想去的活动。 请让我知道这是否对您有帮助。

您所说的“起始页”是什么意思,它是一项活动?您所说的“起始页”是什么意思,它是一项活动?应用程序将停止:(当我单击AlertDialog中的“确定”按钮时)(应用程序将停止:(当我单击AlertDialog中的“确定”按钮时):(