Android日期/时间选择器(工具类)
来源:互联网 发布:网络宣传部 编辑:程序博客网 时间:2024/06/08 13:18
/** * 日期用法:DataPickDialogUtil dataPickDialogUtil = new DataPickDialogUtil(当前类.this); dataPickDialogUtil.dateTimePicKDialog(textview); 时间用法:DataPickDialogUtil timePickDialogUtil = new DataPickDialogUtil(当前类.this); timePickDialogUtil.TimePicKDialog(textview); * 日期/时间选择器 * Created by zyz on 2015/9/29. */public class DataPickDialogUtil{ private DatePicker datePicker; private TimePicker timePicker; private Activity activity; private AlertDialog ad; /** * 日期时间弹出选择框构造函数 * * @param activity * :调用的父activity * @param * */ public DataPickDialogUtil(Activity activity) { this.activity = activity; } /** * 弹出日期时间选择框方法 * * @param inputDate * :为需要设置的日期时间文本编辑框 * @return */ public AlertDialog dateTimePicKDialog(final TextView inputDate) { LinearLayout dateTimeLayout = (LinearLayout) activity .getLayoutInflater().inflate(R.layout.common_datetime, null); datePicker = (DatePicker) dateTimeLayout.findViewById(R.id.datepicker); ad = new AlertDialog.Builder(activity) .setTitle("请设置时间") .setView(dateTimeLayout) .setPositiveButton("设置", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { StringBuffer sb = new StringBuffer(); sb.append(String.format("%d-%02d-%02d", datePicker.getYear(), datePicker.getMonth() + 1, datePicker.getDayOfMonth())); inputDate.setText(sb.toString()); dialog.cancel(); } }) .setNegativeButton("取消", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) {// inputDate.setText(""); } }).show(); return ad; } public AlertDialog TimePicKDialog(final TextView inputDate) { LinearLayout dateTimeLayout = (LinearLayout) activity .getLayoutInflater().inflate(R.layout.common_datetime, null); datePicker = (DatePicker) dateTimeLayout.findViewById(R.id.datepicker); timePicker = (TimePicker) dateTimeLayout.findViewById(R.id.timepicker); datePicker.setVisibility(View.GONE); timePicker.setVisibility(View.VISIBLE); //是否使用24小时制 timePicker.setIs24HourView(true); ad = new AlertDialog.Builder(activity) .setTitle("请设置时间") .setView(dateTimeLayout) .setPositiveButton("设置", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { inputDate.setText(timePicker.getCurrentHour()+":"+timePicker.getCurrentMinute()); dialog.cancel(); } }) .setNegativeButton("取消", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) {// inputDate.setText(""); } }).show(); return ad; }}
0 0
- Android日期/时间选择器(工具类)
- android 日期时间选择器
- Android 日期时间选择器
- android 日期时间选择器
- Android 时间日期选择器
- Android 日期时间选择器
- android时间日期选择器,监听
- android日期和时间选择器
- Android 日期和时间选择器
- Android选择器类库,包括日期时间选择器、单项选择器、地址选择器、颜色选择器、文件目录选择器、数字选择器、星座选择器等
- Android选择器类库,包括日期时间选择器、单项选择器、地址选择器、颜色选择器、文件目录选择器、数字选择器、星座选择器等
- Android开发之自定义DataTimePicker(日期时间选择器)
- Android 日期时间等转换工具类
- android 时间日期选择工具类
- Android仿iPhone的日期时间选择器
- Android 时间日期选择器的用法
- android日期与时间滑动选择器
- Android之日期时间选择器使用方法
- SSH菜鸟学习___更新中。。
- 第六章 注解式控制器详解(3)
- 在Xcode中使用Git进行源码版本控制
- Django中提供大内容(或大文件)下载
- 抓出where使用且未建索引且指定选择性的列
- Android日期/时间选择器(工具类)
- 免费的论文查重网站
- spring security(转载)
- ibus的输入词库限制,让ibus能输"略"
- 第六章 注解式控制器详解(4)
- 正则表达式
- 监听软件被卸载
- Android Drawable中shape详解
- delete 和truncate 区别