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();
}
分享题目:android常用对话框
本文来源:http://myzitong.com/article/jscdhd.html