Question

I am trying to open a Dialog box when pressing on a button of a dialog box. --> buttonPressed --> Dialog1 --> Dialog2

the first dialog box gets created as following:

(When button is pressed):

final Dialog dialog = new Dialog(context);
dialog.setContentView(R.layout.dialog1);         //<-- dialog1 contains a button
final Button button1 = (Button)dialog.findViewById(R.id.button1);  //<--in dialog1

button1.setOnClickListener(new View.OnClickListener() {
    public void onClick(View v) {
        //A NEW DIALOG BOX SHOULD APPEAR HERE WHEN BUTTON1 GETS CLICKED
    }
});

dialog.show();

That's my code so far. What I've tried is to close the dialog box and then open up a new Dialog:

dialog.dismiss();
Dialog dialog2 = new Dialog(context);
dialog2.setContentView(R.layout.dialog2);

dialog.show();

But when trying to open a new Dialog box like this I get some error in the Coreographer.class. I assume that's because a closed dialog box can't create a new Dialog box. Now my question is, how would You open a Dialog box from another Dialog box by clicking on it's button?

Was it helpful?

Solution

Try this on button click on dialog

Dialog dialog2 = new Dialog(context);
dialog2.setContentView(R.layout.dialog2);
dialog.dismiss();
dialog2.show();

OTHER TIPS

Instead of using context use

Dialog dialog2 = new Dialog(YourActivityName.this);

Try That

final Dialog dialog1 = new Dialog(context);
dialog.setContentView(R.layout.dialog1);         //<-- dialog1 contains a button
final Button button1 = (Button)dialog1.findViewById(R.id.button1);  //<--in dialog1

button1.setOnClickListener(new View.OnClickListener() {
    public void onClick(View v) {
        //A NEW DIALOG BOX SHOULD APPEAR HERE WHEN BUTTON1 GETS CLICKED
     Dialog dialog2 = new Dialog(context);
     dialog2.setContentView(R.layout.dialog2);
     dialog1.dismiss();
     dialog2.show();
    }
});

dialog.show();
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top