/**
* 确定、取消
* @param view
*/
public void click1(View view){
AlertDialog.Builder builder=new Builder(DialogTest.this);
builder.setIcon(R.drawable.ic_launcher);
builder.setTitle("提示!");
builder.setMessage("托尔斯泰");
builder.setPositiveButton("确定", new OnClickListener() {
@Override
public void onClick(DialogInterface arg0, int arg1) {
}
});
builder.setNegativeButton("取消", new OnClickListener() {
@Override
public void onClick(DialogInterface arg0, int arg1) {
}
});
builder.create().show();
}
/**
* 三个按钮
* @param view
*/
public void click2(View view){
AlertDialog.Builder builder=new Builder(DialogTest.this);
builder.setIcon(R.drawable.ic_launcher);
builder.setTitle("提示!");
builder.setMessage("你喜欢....?");
builder.setPositiveButton("很喜欢", new OnClickListener() {
@Override
public void onClick(DialogInterface arg0, int arg1) {
Toast.makeText(getApplicationContext(), arg1, 1).show();
}
});
builder.setNegativeButton("不喜欢", new OnClickListener() {
@Override
public void onClick(DialogInterface arg0, int arg1) {
Toast.makeText(getApplicationContext(), arg1, 1).show();
}
});
builder.setNeutralButton("喜欢", new OnClickListener() {
@Override
public void onClick(DialogInterface arg0, int arg1) {
Toast.makeText(getApplicationContext(), arg1, 1).show();
}
});
builder.create().show();
}
/**
* 一个输入
* @param view
*/
public void click3(View view){
AlertDialog.Builder builder=new Builder(DialogTest.this);
builder.setIcon(R.drawable.ic_launcher);
builder.setTitle("提示!");
editText=new EditText(getApplicationContext());
builder.setView(editText);
builder.setPositiveButton("很喜欢", new OnClickListener() {
@Override
public void onClick(DialogInterface arg0, int arg1) {
Toast.makeText(getApplicationContext(), editText.getText().toString(), 1).show();
}
});
builder.setNegativeButton("不喜欢", new OnClickListener() {
@Override
public void onClick(DialogInterface arg0, int arg1) {
Toast.makeText(getApplicationContext(), editText.getText().toString(), 1).show();
}
});
builder.create().show();
}
/**
* 单选
* @param view
*/
public void click4(View view){
AlertDialog.Builder builder=new Builder(DialogTest.this);
builder.setIcon(R.drawable.ic_launcher);
builder.setTitle("单选!");
final String items[]={"item1","item2","item3","item4"};
temp=items[0];
builder.setSingleChoiceItems(items, 0, new OnClickListener() {
@Override
public void onClick(DialogInterface arg0, int arg1) {
temp=items[arg1];
}
});
builder.setPositiveButton("很喜欢", new OnClickListener() {
@Override
public void onClick(DialogInterface arg0, int arg1) {
Toast.makeText(getApplicationContext(), arg1+"=="+temp, 1).show();
}
});
builder.setNegativeButton("不喜欢", new OnClickListener() {
@Override
public void onClick(DialogInterface arg0, int arg1) {
Toast.makeText(getApplicationContext(), arg1+"=="+temp, 1).show();
}
});
builder.create().show();
}
/**
* 复选
* @param view
*/
public void click5(View view){
AlertDialog.Builder builder=new Builder(DialogTest.this);
builder.setIcon(R.drawable.ic_launcher);
builder.setTitle("复选!");
final String items[]={"item1","item2","item3","item4"};
boolean checkedItems[]={true,false,false,false};
temps.add(items[0]);
builder.setMultiChoiceItems(items, checkedItems, new OnMultiChoiceClickListener() {
@Override
public void onClick(DialogInterface arg0, int arg1, boolean arg2) {
if(arg2){
temps.add(items[arg1]);
}else{
temps.remove(items[arg1]);
}
}
});
builder.setPositiveButton("很喜欢", new OnClickListener() {
@Override
public void onClick(DialogInterface arg0, int arg1) {
Toast.makeText(getApplicationContext(), arg1+"=="+temps.toString(), 1).show();
}
});
builder.setNegativeButton("不喜欢", new OnClickListener() {
@Override
public void onClick(DialogInterface arg0, int arg1) {
Toast.makeText(getApplicationContext(), arg1+"=="+temps.toString(), 1).show();
}
});
builder.create().show();
}
/**
* 列表
* @param view
*/
public void click6(View view){
AlertDialog.Builder builder=new Builder(DialogTest.this);
builder.setIcon(R.drawable.ic_launcher);
builder.setTitle("列表!");
final String items[]={"item1","item2","item3","item4"};
builder.setItems(items, new OnClickListener() {
@Override
public void onClick(DialogInterface arg0, int arg1) {
temp=items[0];
}
});
builder.setPositiveButton("很喜欢", new OnClickListener() {
@Override
public void onClick(DialogInterface arg0, int arg1) {
Toast.makeText(getApplicationContext(), arg1+"=="+temp, 1).show();
}
});
builder.setNegativeButton("不喜欢", new OnClickListener() {
@Override
public void onClick(DialogInterface arg0, int arg1) {
Toast.makeText(getApplicationContext(), arg1+"=="+temp, 1).show();
}
});
builder.create().show();
}
/**
* 自定义
* @param view
*/
public void click7(View view){
//看不到自定义控件输入的值
/*AlertDialog.Builder builder=new Builder(DialogTest.this);
builder.setIcon(R.drawable.ic_launcher);
builder.setTitle("自定义!");
view=LayoutInflater.from(getApplicationContext()).inflate(R.layout.dd,null);
builder.setView(view);
builder.create().show();*/
Dialog dialog=new Dialog(DialogTest.this);
dialog.setTitle("自定义!");
dialog.setContentView(R.layout.dd);
dialog.show();
}
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。