I have an application that allows the users to delete video files. When I press the delete button, I am using
DialogInterface.OnClickListener dialogClickListener = new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
switch (which) {
case DialogInterface.BUTTON_POSITIVE:
// mycode........
break;
case DialogInterface.BUTTON_NEGATIVE:
// mycode.....
break;
}
}
};
But this message doesn't have a warning or delete icon as we see in android devices. Can anyone help me in getting those icons or using any other alert dialogs that can show those icons?
I tend to use AlertDialog.Builder like they show in the official doc example
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage("Are you sure you want to exit?")
.setCancelable(false)
.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
MyActivity.this.finish();
}
})
.setNegativeButton("No", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.cancel();
}
})
//Set your icon here
.setTitle("Alert!")
.setIcon(R.drawable.icon);
AlertDialog alert = builder.create();
alert.show();//showing the dialog
As for the actual icon look inside your sdk folder/platforms/android version #/data/res/drawable-mdpi or something
i tried to set drawable but it is not showing in the dialog box
hmm, try setting a title too. I think that might be why you're not seeing one. try my edited code.
Thanks alot sir. It worked.. Can you please tell me a bit more about other functions like putting the image in the center etc. Thanks once again
For that, you would have to create a custom dialog with your own predefined view.
@AlamKanak Your edit is just plain wrong...
setIcon()
is overloaded and accepts bothDrawable
instances as well as drawable resource ids!