Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating AlertDialog with Static Methods?

I've completed most of the game I'm attempting to make and throughout the project I've created one particular Activity which also calls a SurfaceView and a Thread. I put an update() method in each of the 3 classes so they each know where the other ones are everytime something changes. Apparently, the only way to do something like this is using static methods... This is fine until a collision occurs in my SurfaceView and I want to tell the Activity what to do. I can relay the information, but then I cannot find a way to make an AlertDialog.

I understand I cannot call showDialog() from a Static method, but I cannot find a way to make a non-static method to call it with and then call that method from a static one. I've been searching for an answer and I've heard something about instantiating the object but I cannot figure out what that means...

If anyone has a good idea to get me around this, please let me know :)

like image 567
Aaron Avatar asked Aug 13 '10 05:08

Aaron


People also ask

What are the methods of AlertDialog builder class?

Alert Dialog code has three methods:setTitle() method for displaying the Alert Dialog box Title. setMessage() method for displaying the message. setIcon() method is used to set the icon on the Alert dialog box.

What is the difference between dialog and AlertDialog?

AlertDialog is a lightweight version of a Dialog. This is supposed to deal with INFORMATIVE matters only, That's the reason why complex interactions with the user are limited. Dialog on the other hand is able to do even more complex things .

How many button options can you use in creating AlertDialog?

AlertDialog. A dialog that can show a title, up to three buttons, a list of selectable items, or a custom layout.

What is the structure of an AlertDialog?

Android AlertDialog is composed of three regions: title, content area and action buttons.


1 Answers

Here is what I used:

public static void messageDialog(Activity a, String title, String message){
    AlertDialog.Builder dialog = new AlertDialog.Builder(a);
    dialog.setTitle(title);
    dialog.setMessage(message);
    dialog.setNeutralButton("OK", null);
    dialog.create().show();     

}
like image 86
Joe Avatar answered Oct 03 '22 01:10

Joe