Reputation: 255
I have created a preference activity that has a dialog. The dialog has two buttons CANCEL and ADD. upon the click of the add button another dialog should open that has two edit text box's for entering the MAC address and the Device Name
How can I handle the on Click of the button in the preference screen dialog. If I can access the on click of the dialog then I can open another activity.
Upvotes: 0
Views: 478
Reputation: 45493
You can supply your own DialogInterface.OnClickListener
for every default button of a dialog. Here's a copy-paste from the Dialogs topic on developer.android.com:
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage("Are you sure you want to exit?")
.setCancelable(false)
.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
MyActivity.this.finish();
}
})
.setNegativeButton("No", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.cancel();
}
});
AlertDialog alert = builder.create();
Alternatively you can create your own dialog, with a custom layout displaying whatever widgets you like. Using this approach you can hook up regular View.OnClickListener
to buttons and put the logic in there.
Upvotes: 1