0

有什么方法可以创建一个对话框,单击该对话框中的一个按钮,该按钮将转到另一个对话框,然后单击新对话框中的另一个按钮,将您带到上一个对话框?

Dialog - > Dialog2 -> Dialog 

这是我的代码:

private void showIBW() {

    final String[] frame = { "Small", "medium", "large" };

    AlertDialog.Builder framechoice = new AlertDialog.Builder(this);
    framechoice.setTitle("please choose your frame size");
    framechoice.setNeutralButton("what's this?",
            new DialogInterface.OnClickListener() {

                public void onClick(DialogInterface dialog, int which) {

                    AlertDialog.Builder help = new AlertDialog.Builder(getApplicationContext());
                    help.setTitle("Frame explanation");
                    help.setMessage("cheikh is not helpful");
                    help.setNeutralButton("okay thanks", new DialogInterface.OnClickListener() {

                        public void onClick(DialogInterface dialog, int which) {

                            ////// Here i want this button to get me back to the "Framechoice" dialog///


                        }
                    });
                    help.create();
                    help.show();
                }

            });
    framechoice.setItems(frame, new DialogInterface.OnClickListener() {

        public void onClick(DialogInterface dialog, int which) {

            SharedPreferences customSharedPreference = getSharedPreferences(
                    "myCustomSharedPrefs", Activity.MODE_PRIVATE);

            Toast.makeText(getApplicationContext(), frame[which],
                    Toast.LENGTH_LONG).show();

            String Height = customSharedPreference.getString("heightpref",
                    null);
            float height = Integer.parseInt(Height);

            float weight1 = ((height / 100) * (height / 100)) * 20;
            float weight2 = ((height / 100) * (height / 100)) * 25;

            AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(
                    CalculationsActivity.this);
            dialogBuilder.setTitle("Ideal weight calculator");

            dialogBuilder
                    .setMessage("Your ideal weight is between:\n           "
                            + Math.round(weight1)
                            + " Kg to "
                            + Math.round(weight2) + " kg");
            dialogBuilder.setPositiveButton("ok",
                    new DialogInterface.OnClickListener() {

                        public void onClick(DialogInterface dialog,
                                int which) {

                            Intent u = new Intent();
                            u.setClass(CalculationsActivity.this,
                                    CalculationsActivity.class);
                            startActivity(u);
                        }
                    }).create();
            dialogBuilder.show();

        }

    }).create();
    framechoice.show();


}
4

2 回答 2

0

如果您正在寻找解决方案

////// 我希望这个按钮让我回到“Framechoice”对话框///

将其替换为

dialog.cancel();

看看这是否有帮助。

于 2012-05-06T13:59:38.843 回答
0

您应该将您的活动用作 AlertDialog.Builder 的上下文,而不是应用程序的 c 上下文。

更多信息在这里:

为什么 AlertDialog.Builder(Context context) 只接受 Activity 作为参数?

https://groups.google.com/forum/?fromgroups#!msg/android-beginners/22dlKekP_V0/t8XfhoDlsQsJ

于 2012-05-06T14:01:20.327 回答