How To Create Custom Messagebox In Android Application?
I am new to Android application, i want to show confirm MessageBox in my Android application and want to get result (which button clicked, as in .Net Windows Application). Please r
Solution 1:
Please try this
DialogInterface.OnClickListenerdialogClickListener=newDialogInterface.OnClickListener() {
@OverridepublicvoidonClick(DialogInterface dialog, int which) {
switch (which){
case DialogInterface.BUTTON_POSITIVE:
//Yes button clickedbreak;
case DialogInterface.BUTTON_NEGATIVE:
//No button clickedbreak;
}
}
};
AlertDialog.Builderbuilder=newAlertDialog.Builder(this);
builder.setMessage("Are you sure?").setPositiveButton("Yes", dialogClickListener)
.setNegativeButton("No", dialogClickListener).show();
Solution 2:
To get the result of the AlertDialog Please try as below,
String Result="";
publicvoidAlert(String text, String title)
{
AlertDialog dialog=new AlertDialog.Builder(context).create();
dialog.setTitle(title);
dialog.setMessage(text);
if(!title.equals("") && !text.equals(""))
{
dialog.setButton("OK",
new DialogInterface.OnClickListener()
{
publicvoidonClick(DialogInterface dialog, int whichButton)
{
Result="OK";
}
});
dialog.setButton2("Cancel",
new DialogInterface.OnClickListener()
{
publicvoidonClick(DialogInterface dialog, int whichButton)
{
Result="Cancel";
}
});
}
dialog.show();
}
Thank you.
Post a Comment for "How To Create Custom Messagebox In Android Application?"