AlterDialog:确认取消警告提示框
public voID showAlertDialog(VIEw vIEw){ AlertDialog.Builder dialog = new AlertDialog.Builder(MainActivity.this); dialog.setTitle("这是一个AlertDialog"); dialog.setMessage("对话框详细信息:请选择“取消”还是“确认”?"); dialog.setCancelable(false);//不能取消 dialog.setPositivebutton("确认",new DialogInterface.OnClickListener(){ @OverrIDe public voID onClick(DialogInterface dialog,int which){ TextVIEw tv1 = (TextVIEw)findVIEwByID(R.ID.textVIEw); tv1.setText("你选择了确认!"); } }); dialog.setNegativebutton("取消", new DialogInterface.OnClickListener(){ @OverrIDe public voID onClick(DialogInterface dialog, int which){ TextVIEw tv1 = (TextVIEw)findVIEwByID(R.ID.textVIEw); } }); dialog.show();}
ProgressDialog进度条框:
public voID showProgressDialog(VIEw vIEw){ ProgressDialog progressDialog = new ProgressDialog(MainActivity.this); progressDialog.setTitle("这是一个进度条对话框"); progressDialog.setMessage("请耐心等待,正在处理数据..."); progressDialog.setCancelable(true); progressDialog.show();
}
DatePickerDialog日期选择框:
public voID showDateDialog(VIEw vIEw){ DatePickerDialog.OnDateSetListeneronDateSetListener= new DatePickerDialog.OnDateSetListener(){ @OverrIDe public voID onDateSet(DatePicker vIEw, int year, int month, int dayOfMonth){ TextVIEw tv1 = (TextVIEw)findVIEwByID(R.ID.textVIEw); String theDate = String.format("你选择的日期:%d年%月%日", year, month, dayOfMonth); tv1.setText(theDate); } }; DatePickerDialog datePickerDialog = new DatePickerDialog(MainActivity.this, onDateSetListener, 2017, 5, 1); datAPIckerDialog.show();}
TImePickerDialog 时间选择器:
public voID showTimeDialog(VIEw vIEw){ TimePickerDialog.OnTimeSetListeneronTimeSetListener = newTimePickerDialog.OnTimeSetListener(){ @OverrIDe public voID onTimeSet(TimePicker vIEw, int hourOfDay, int minute){ TextVIEw tv1 = (TextVIEw)findVIEwByID(R.ID.textVIEw); String theTime = String.format("你选择的时间:%d:%d",hourOfDay, minute); tv1.setText(theTime); } }; TimePickerDialog timePickerDialog = new TimePickerDialog(MainActivity.this, onTimeSetListener, 0,0,true); timePickerDialog.show();}
总结
以上是内存溢出为你收集整理的android常用的四种对话框java代码全部内容,希望文章能够帮你解决android常用的四种对话框java代码所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)