【Demo 0002】Android 提醒框

本章学习要点:

 

//==: Alert Dialog

void showAlertDialog() {

final Builder builder = new AlertDialog.Builder(this);

builder.setTitle("AlertDialog");

builder.setMessage("This is a alert message!");

builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {

@Override

public void onClick(DialogInterface dialog, int which) {

 

}

});

builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {

@Override

public void onClick(DialogInterface dialog, int which) {

 

}

 

});

AlertDialog alertDialog = builder.create();

alertDialog.show();

}

 

//==: Option Alert Dialog

void showOptionDialog() {

 

final String[] items = {"Apple", "Banana", "Pear", "Tomato" };

 

final AlertDialog.Builder builder = new AlertDialog.Builder(this);

builder.setTitle("Which fruit do you like?");

builder.setSingleChoiceItems(items, 0, new DialogInterface.OnClickListener() {

 

@Override

public void onClick(DialogInterface dialog, int which) {

StringBuilder sb = new StringBuilder();

sb.append(items[which]);

sb.append(" is very good!");

 

Toast toast = Toast.makeText(getApplicationContext(), sb.toString(), Toast.LENGTH_SHORT);

toast.show();

}

});

 

builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {

 

@Override

public void onClick(DialogInterface dialog, int which) {

return;

}

});

 

AlertDialog alertDialog = builder.create();

alertDialog.show();

}

 

//==: Toast Dialog 

void showToastDialog() {

Toast toast = Toast.makeText(getApplicationContext(), "This is a toast dialog", Toast.LENGTH_LONG);

toast.show();

}

posted @ 2013-11-08 22:36  zTercel  阅读(138)  评论(0编辑  收藏  举报