Saturday, 31 August 2013

Android alertdialogue returning boolean

Android alertdialogue returning boolean

I am wring a simple script where there is a confirmation box of two
options. I need to cal it more than one time in an activity. So i made a
method to do that. Based on the returning boolean i want to write the
conditional statements.
private void showConfirmation() {
// UserFunctions userFunctions = null;
// TODO Auto-generated methodastub
AlertDialog.Builder alertDialogBuilder = new
AlertDialog.Builder(ProfileActivity.this);
// set title
alertDialogBuilder.setTitle("Mobile Gullak");
// set dialog message
alertDialogBuilder.setMessage("Please update the unfilled
fields.").setCancelable(false)
.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int id) {
dialog.cancel();
return false;
}
}).setNegativeButton("Later on", new
DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int id) {
return true;
}
});
// create alert dialog
AlertDialog alertDialog = alertDialogBuilder.create();
// show it
alertDialog.show();
return false;
}
if(showConfirmation()){
// do something.
}

No comments:

Post a Comment