jkmcgee
jkmcgee

Reputation: 101

How do I use the showAlert method in Android?

I am trying to debug something and want to pop up a message dialog box. Eclipse is telling me that it wants me to "Create Method showAlert(string, string, string, boolean)"

I have imported this import android.content.DialogInterface;

what step am I missing?

Upvotes: 5

Views: 11928

Answers (3)

Diego Torres Milano
Diego Torres Milano

Reputation: 69228

If you are only showing a debug message you may try Toast.makeText():

Toast.makeText(context, "Hi there!", Toast.LENGTH_SHORT).show();

Don't forget to call show().

Upvotes: 5

MrSnowflake
MrSnowflake

Reputation: 4742

If you are trying to create and display an AlertDialog, you should user AlertDialog.Builder for example.

DialogInterface, is as its name implies, an interface and only has 2 methods: cancel() and dismiss().

Creating an AlertDialog is fairly easy:

new AlertDialog.Builder(this)
.setTitle("Some Title")
.setMessage("some message")
.setPositiveButton("OK", new OnClickListener() {
    public void onClick(DialogInterface arg0, int arg1) {
        // Some stuff to do when ok got clicked
    }
})
.setNegativeButton("cancel", new OnClickListener() {
    public void onClick(DialogInterface arg0, int arg1) {
        // Some stuff to do when cancel got clicked
    }
})
.show();

That shows a simple AlertDialog.

A tip: Check Activity.showDialog(int) and Activity.onCreateDialog() they make your life easier when using dialogs.

Upvotes: 6

Justin
Justin

Reputation: 9791

Looks like you might have a parameter-type mismatch. Check that your parameters are actually Strings or booleans. Maybe you need to be calling toString() on your objects?

Upvotes: 0

Related Questions