Here’s my code:
myButton.setOnClickListener( new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface arg0, int arg1) {
// TODO Auto-generated method stub
}
});
Which gives me this error:
The method setOnClickListener(View.OnClickListener) in the type View is not applicable for the arguments (new DialogInterface.OnClickListener(){})
I have DialogInterface and DialogInterface.OnClickListener imported. “myButton” is in a Dialog.
Here’s my current setup. button1 launches the Dialog, and button2 is contained within the Dialog.
private void setOnClickListeners() {
button1.setOnClickListener( new OnClickListener() {
@Override
public void onClick(View arg0) {
//set up dialog
Dialog dialog = new Dialog(WorkScreen.this);
dialog.setContentView(R.layout.dialog_layout);
dialog.setTitle("My Dialog");
dialog.setCancelable(true);
dialog.show();
}
});
button2.setOnClickListener( new OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
}
});
}
This crashes when the Activity loads. I’ve also tried moving the Dialog declaration to the top of the class and initializing it in the onCreate, but it didn’t change anything. Ideas?
use DialogInterface.OnClickListener when you need to handle buttons in Dialogs only but View.onclickListener to handle views in an Activiy .
i create my custom dialog and handle the button in dialog in this class