I have an alertdialog that I am showing, but no matter what I do, it shows alertdialog with an empty header and message. The icon, the “Positive” button and the “negative” buttons are displayed with the correct descriptions. Here are the snippets of the code I'm using: In the manifest file:
<uses-sdk android:minSdkVersion="5" android:targetSdkVersion="16" />
In my code, I declare:
import android.app.AlertDialog; import android.content.Context; import android.content.DialogInterface;
I also declare the context:
final Context context = this;
I place my warning in:
public void confirm() { AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(context); // set title alertDialogBuilder.setTitle("This is title"); alertDialogBuilder.setIcon(R.drawable.ic_delete); // set dialog message alertDialogBuilder .setMessage("This is the message") .setCancelable(false) .setPositiveButton(R.string.yes,new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog,int id) { // if this button is clicked, close // current activity MainActivity.this.finish(); } }) .setNegativeButton(R.string.no,new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog,int id) { // if this button is clicked, just close // the dialog box and do nothing dialog.cancel(); } }); // create alert dialog AlertDialog alertDialog = alertDialogBuilder.create(); // show it alertDialog.show(); }
Then I call confirmation where I need it, for example:
confirm();
A warning will appear. The icon is set. SetPositiveButton is good and contains the correct description. Set of NegativeButton is good and contains the correct description.
Title is empty Message is empty
Any ideas?
source share