dialog - How do I create an Appwide method for AlertDialog in Android -
I have some places in my app where I should make a warning to pop up and ask a user some questions , Then callback with the selected answer.
In some places I want to do this in the Custom Non-Activity / Piece Objects.
I was trying to make a method in my class that comes from the application which will display an AlertDialog, but I'm always having a reference problem and crashing. It is a snippet from my app class Context = getApplicationContext ();
public static zero show alert (string title, string message) {AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder (reference); // Set Headline DialogBuilder.setTitle ("Your Title"); // Set Dialogue Message Warning Delogballer .Setmasez ("Yes click to exit!") .Setcable (false) .cat positive button ("Yes", New Dialog interface. OnClickList () {Public click on Zero (Dialogue Interface dialog, int id) {// if this button is clicked, close / current activity}}) .setNegativeButton ("No", New DialogInterface.OnClickListener () {public void onClick (DialogInterface dialog, int id) {// If this button is clicked, just close it A. // dialog box and do nothing dialog.cancel ();}}); // Alert Dialog Warning Dialog = Alert DLObuilder Create (); // show it alert dialogue.show (); }
Why do I need to set my reference, so it will not crash? Or is it a better way to do it altogether?
Thanks, Alec
Comments
Post a Comment