/**
* 確定、取消
* @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();
}
/**
* 復(fù)選
* @param view
*/
public void click5(View view){
AlertDialog.Builder builder=new Builder(DialogTest.this);
builder.setIcon(R.drawable.ic_launcher);
builder.setTitle("復(fù)選!");
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){
創(chuàng)新互聯(lián)專注于宣漢網(wǎng)站建設(shè)服務(wù)及定制,我們擁有豐富的企業(yè)做網(wǎng)站經(jīng)驗。 熱誠為您提供宣漢營銷型網(wǎng)站建設(shè),宣漢網(wǎng)站制作、宣漢網(wǎng)頁設(shè)計、宣漢網(wǎng)站官網(wǎng)定制、微信小程序服務(wù),打造宣漢網(wǎng)絡(luò)公司原創(chuàng)品牌,更為您提供宣漢網(wǎng)站排名全網(wǎng)營銷落地服務(wù)。
//看不到自定義控件輸入的值
/*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();
}