0

I followed a tutorial to add buttons to a dialog, sorry, forgot the link, here is my code to display a dialog:

final Dialog dialog = new Dialog(MainActivity.this);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setContentView(R.layout.about);
dialog.setCancelable(true);

Button buttonEmail = (Button) dialog.findViewById(R.id.aboutQuit);
buttonEmail.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
     String inURL = "mailto:my@email.com";
     openWebURL(inURL);
}
});
Button buttonQuit = (Button) dialog.findViewById(R.id.aboutQuit);
buttonQuit.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
     dialog.dismiss();
}
});

And it works, it display the dialog and all but it will only set one of the buttons, depending in what order I put them, how can I fix this, thanks for your time 'n' help, zeokila ;)

Alexandre Hitchcox
  • 2,704
  • 5
  • 22
  • 33

2 Answers2

2

You are setting setOnClickListener() two times only for R.id.aboutQuit button. try to change the Id properly.

Animesh Sinha
  • 1,045
  • 9
  • 16
1

First you have an error when setting up the listeners. The following line:

Button buttonEmail = (Button) dialog.findViewById(R.id.aboutQuit);

is getting the quit button not the email. You should change R.id.aboutQuit to your email button ID.

For the other issue you should post the layout with ID R.layout.about.

azertiti
  • 3,150
  • 17
  • 19