Tuesday, January 22, 2013

Android Dialogs



Alerts provide a quick message to the user outside of the application’s main UI. It can be
in an overlay window such as a Toast or AlertDialog box. It can also be in the notification
bar at the top of the screen.




The Toast method has been introduced in the previous chapter in a compact form:
Toast.makeText(this, "text", Toast.LENGTH_SHORT).show();
It can also be written as a multiline command:
Toast tst = Toast.makeText(this, "text", Toast.LENGTH_SHORT);
tst.show();






Using an Alert Dialog Box
Providing a user with an alert and up to three buttons


AlertDialog dialog = new AlertDialog.Builder(this).create();
dialog.setMessage("Your final score: " + mScore + "/" + PERFECT_SCORE);
dialog.setButton(DialogInterface.BUTTON_POSITIVE, "Try this level again",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
mScore = 0;
start_level();
}
});
dialog.setButton(DialogInterface.BUTTON_NEGATIVE, "Advance to next level",
new DialogInterface.OnClickListener() {

No comments:

Post a Comment