android 常用对话框
/**
* 确定、取消
* @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();
}
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。