0

Is there any way to have a dialog, click on a button in that dialog that will take to another dialog and then click on another button in the new dialog that will take you to the previous dialog?

Dialog - > Dialog2 -> Dialog 

This is my code:

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();


}
Ant4res
  • 1,217
  • 1
  • 18
  • 36
callback
  • 3,981
  • 1
  • 31
  • 55

2 Answers2

0

if you are looking for the solution to

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

replace that with

dialog.cancel();

see if this help.

Gaurav Agarwal
  • 18,754
  • 29
  • 105
  • 166
  • Why you are trying to do call `setNeutralButton` and 'setItems' in the same AlertDialog? Can you show me an image of Dialog how Dilog box will look with both of these? – Gaurav Agarwal May 06 '12 at 19:40
0

You should use your activity as context for AlertDialog.Builder and not the application's c context.

more info here:

Why does AlertDialog.Builder(Context context) only accepts Activity as a parameter?

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

Community
  • 1
  • 1
Ran
  • 4,117
  • 4
  • 44
  • 70
  • 1
    It will help other if you could edit answer to include a little informative description or pointer to what is the difference between Application and Activity Context? – Gaurav Agarwal May 06 '12 at 14:12