标签:button cli set class ice text osi ide over
单选对话框,顾名思义就是只能选一项(setSingleChoiceItems(Items,))
1 public void click(View v){ 2 //创建对话框类 3 AlertDialog.Builder builder = new AlertDialog.Builder(this); 4 //定义item选项 5 final String items[] = new String[]{"一只","两只","三只"}; 6 builder.setTitle("没有什么事是一只口红解决不了的,如果有那就两只")//设置标题 7 .setSingleChoiceItems(items,-1, new DialogInterface.OnClickListener() {//设置单选 8 @Override 9 public void onClick(DialogInterface dialogInterface, int i) { 10 Toast.makeText(MainActivity.this,"你选择了用"+items[i]+"口红解决问题",Toast.LENGTH_SHORT).show(); 11 } 12 }).setPositiveButton("是的", new DialogInterface.OnClickListener() { 13 @Override 14 public void onClick(DialogInterface dialogInterface, int i) { 15 Toast.makeText(MainActivity.this,"我选择了是",Toast.LENGTH_SHORT).show(); 16 } 17 }).setNegativeButton("取消", new DialogInterface.OnClickListener() { 18 @Override 19 public void onClick(DialogInterface dialogInterface, int i) { 20 Toast.makeText(MainActivity.this,"我选择了取消,因为我相信口红解决不了",Toast.LENGTH_SHORT).show(); 21 } 22 }).show(); 23 }
标签:button cli set class ice text osi ide over
原文地址:http://www.cnblogs.com/Coderwei2016/p/6024941.html