标签:
public void click1(View view){
/**/对话框的创建器**
AlertDialog.Builder builder = new Builder(this);
builder.setTitle("我是对话框");
builder.setMessage("对话框显示的内容");
/////***********************************************************
builder.setPositiveButton("dsad", new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
}
});
builder.setPositiveButton("确定", new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Toast.makeText(getApplicationContext(), "确定被点击了", 0).show();
}
});
builder.setNegativeButton("取消", new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
//什么都不写默认实现就是关闭掉对话框
}
});
/////**************************************************************
builder.setCancelable(false); //对话框不可以取消掉,只能选择其中的选项
builder.show();//builder.create().show();
}
/**
*** 单选对话框**
* @param view
*/
public void click2(View view){
//对话框的创建器
AlertDialog.Builder builder = new Builder(this);
builder.setTitle("请选择您的性别");
final String[] items = {"男","女","未知"};
builder.setSingleChoiceItems(items, 2, new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Toast.makeText(getApplicationContext(), "您的性别:"+items[which], 0).show();
dialog.dismiss();
}
});
builder.show(); //相当于builder。creat().show();
}
/**
* **多选对话框**
* @param view
*/
public void click3(View view){
//对话框的创建器
AlertDialog.Builder builder = new Builder(this);
builder.setTitle("请选择你最爱吃的水果");
final String[] items={"苹果","梨","菠萝","香蕉","黄瓜"};
final boolean[] result =new boolean[]{true,false,true,false,false};
builder.setMultiChoiceItems(items, result, new OnMultiChoiceClickListener() {
@Override
public void onClick(DialogInterface dialog, int which, boolean isChecked) {
Toast.makeText(getApplicationContext(), items[which]+isChecked, 0).show();
result[which] = isChecked;
}
});
builder.setPositiveButton("提交", new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
StringBuffer sb = new StringBuffer();
for(int i=0;i<result.length;i++){
if(result[i]){
sb.append(items[i]+",");
}
}
Toast.makeText(getApplicationContext(), "您选中了,"+sb.toString(), 0).show();
}
});
//builder.create().show();
builder.show(); //相当于builder。creat().show();
}
**//进度条对话框**
public void click4(View view){
ProgressDialog pd = new ProgressDialog(this);
pd.setTitle("提醒");
pd.setMessage("正在加载数据...请稍等。");
pd.show();
}
**//带进度的进度条对话框**
public void click5(View view){
final ProgressDialog pd = new ProgressDialog(this);
pd.setTitle("提醒");
pd.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
pd.setMax(100);
pd.setMessage("正在加载数据...请稍等。");
pd.show();
new Thread(){
public void run() {
for(int i = 0;i<100;i++){
try {
Thread.sleep(40);
} catch (Exception e) {
e.printStackTrace();
}
pd.setProgress(i);
}
pd.dismiss();
};
}.start();
}
标签:
原文地址:http://blog.csdn.net/xs15073722800/article/details/51334617