How to use showAlert method in Android?

I am trying to debug something and want to open a message dialog. Eclipse tells me that he wants me to "Create Method showAlert (string, string, string, boolean)"

I imported this import android.content.DialogInterface;

which step am i missing?

+5
source share
3 answers

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

DialogInterface, as the name implies, has an interface and has only two methods: cancel () and reject ().

Creating an AlertDialog is pretty simple:

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();

This shows a simple AlertDialog.

: Activity.showDialog(int) Activity.onCreateDialog(), .

+6

, Toast.makeText():

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

show().

+5

It looks like you might have a parameter type mismatch. Make sure your parameters are actually strings or booleans. Perhaps you need to call toString()on your objects?

0
source

All Articles