Last active
December 7, 2016 21:03
-
-
Save kostovtd/dbbacf70012793c317ac4c3b3c1f445c to your computer and use it in GitHub Desktop.
A code snippet for overriding the behavior of AlertDialog buttons
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
final AlertDialog dialog = new AlertDialog.Builder(context) | |
.setView(v) | |
.setTitle(R.string.my_title) | |
.setPositiveButton(android.R.string.ok, null) //Set to null. We override the onclick | |
.setNegativeButton(android.R.string.cancel, null) | |
.create(); | |
dialog.setOnShowListener(new DialogInterface.OnShowListener() { | |
@Override | |
public void onShow(DialogInterface dialog) { | |
Button button = ((AlertDialog) dialog).getButton(AlertDialog.BUTTON_POSITIVE); | |
button.setOnClickListener(new View.OnClickListener() { | |
@Override | |
public void onClick(View view) { | |
// TODO Do something | |
} | |
}); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment