标准弹出框
< android:id="@+id/btno1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="标准弹出框"/>
public void myOnClick(View view){
switch (view.getId()) {
case R.id.btno1://标准弹出框
AlertDialog.Builder b1=new AlertDialog.Builder(this);
b1.setTitle("来短信了");
b1.setIcon(R.drawable.ke);//设置目标
b1.setMessage("恭喜你这条短信是假的");
b1.setPositiveButton("取消", new OnClickListener() {
@Override
public void onClick(DialogInterface arg0, int arg1) {
// TODO Auto-generated method stub
Log.v("TAG", "这是取消按钮");
}
});
b1.setNegativeButton("删除", null);
b1.setNeutralButton("回复", null);
b1.setCancelable(false);//设置返回键是否可能
break;
自定义弹出框
< android:id="@+id/btno2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="自定义弹出框"/>
case R.id.btno2:
Dialog d=new Dialog(this);
d.setTitle("这是自定义框");
d.setContentView(R.layout.dialog_view);
Button btn=(Button) d.findViewById(R.id.btn_d);
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
Log.v("TAG", "被点击了");
}
});
d.show();
break;
进度框
android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="进度框"/> case R.id.btn03://进度框 final ProgressDialog p=new ProgressDialog(this); p.setTitle("进度框"); p.setIcon(R.drawable.bird); p.setMessage("当前进度是10%"); p.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL); p.setMax(100); p.incrementSecondaryProgressBy(1); p.setButton("确定", new OnClickListener() { @Override public void onClick(DialogInterface arg0, int arg1) { // TODO Auto-generated method stub Log.v("TAG", "确定"); } }); p.show(); break; 单选框 < android:id="@+id/btno4" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="单选弹出框"/> case R.id.btn04: AlertDialog.Builder b2=new AlertDialog.Builder(this); b2.setTitle("单选框(籍贯)"); b2.setIcon(R.drawable.bird); final String[] items=new String[]{"怀化","长沙","张家界","株洲"}; b2.setSingleChoiceItems(items, 2, new OnClickListener() { @Override public void onClick(DialogInterface arg0, int arg1) { // TODO Auto-generated method stub Log.v("TAG", "items[arg1]"); } }); b2.setPositiveButton("确定", null); b2.setNegativeButton("取消", null); b2.show(); break; 多选框 < android:id="@+id/btno5" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="多选弹出框"/> case R.id.btn05: AlertDialog.Builder b3=new AlertDialog.Builder(this); b3.setTitle("多选框(爱好)"); b3.setIcon(R.drawable.bird); final String[] hobby=new String[]{"吃饭","睡觉","打豆豆","篮球","敲代码"}; b3.setMultiChoiceItems(hobby, new boolean[]{false,false,false,true,true,true},new OnMultiChoiceClickListener() { @Override public void onClick(DialogInterface arg0, int arg1, boolean arg2) { // TODO Auto-generated method stub Log.v("TAG", "你点击了"+hobby[arg1]+"/"+arg2); } }); b3.setPositiveButton("确定", null); b3.setNegativeButton("取消", null); b3.show(); break; 时间弹出框 android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="时间弹出框"/> case R.id.btn06: Date dt=new Date(); TimePickerDialog tp=new TimePickerDialog(this, new OnTimeSetListener() { @Override public void onTimeSet(TimePicker arg0, int arg1, int arg2) { // TODO Auto-generated method stub Log.v("TAG", "当前的时间是"+arg1+":"+arg2); } }, dt.getHours(),dt.getMinutes(), true); tp.show(); break; 日期弹出框 android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="日期弹出框"/> case R.id.btn07: Calendar cl=Calendar.getInstance(); DatePickerDialog dp=new DatePickerDialog(this, new OnDateSetListener() { @Override public void onDateSet(DatePicker arg0, int arg1, int arg2, int arg3) { // TODO Auto-generated method stub Log.v("TAG","当前时间是"+arg1+"年"+(arg2+1)+"月"+arg3+"日"); } }, cl.get(Calendar.YEAR), cl.get(Calendar.MONTH), cl.get(Calendar.DATE)); dp.show(); break;