Closed UNOAlterEgo closed 8 years ago
How can I implement an alert dialog to ask the user if they really want to logout?
you should write something like this:
`AlertDialog.Builder alertDialog = new AlertDialog.Builder(CONTEXT_YOU_WANT)); //Read Update
LayoutInflater inflater = getLayoutInflater();
View dialogLayout = inflater.inflate(R.layout.geeft_image_dialog, null);
alertDialog.setView(dialogLayout);
alertDialog.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
//the positive button should call the "logout method"
@Override
public void onClick(DialogInterface dialog, int which) {
//here you can add functions
LOGOUT_METHOD
}
});
alertDialog.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
//cancel the intent
@Override
public void onClick(DialogInterface dialog, int which) {
//here you can add functions
dialog.dismiss();
}
});
//On click, the user visualize can visualize some infos about the geefter
AlertDialog dialog = alertDialog.create();
//the context i had to use is the context of the dialog! not the context of the
//set the title
dialog.setTitle("TITLE OF THE DIALOG")
//if you don't want the title
//use this: dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.getWindow().getAttributes().windowAnimations = R.style.dialog_animation;
dialog.setMessage("MESSAGE YOU WANT TO RETURN TO THE USER");
dialog.show(); //<-- See This!
thanks my code is similar but I created a style to handle the layout
logout implemented with alert dialog
Description: Allowing user to logout from app Requires: intent, calls to BaaS backend Status: Coding Time: 2 Hours