您好,登錄后才能下訂單哦!
/**
* 確定、取消
* @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進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。