当前位置: 代码迷 >> 综合 >> 时间选择器
  详细解决方案

时间选择器

热度:4   发布时间:2024-03-08 20:31:46.0
/*** 日期* themeResId 1-5任意输入(5种不同的时间选择器)* <p>* tvTime 设置时间* <p>* calendar  创建Calendar*/public void showDatePickerDialog(Activity activity, int themeResId, final TextView tvTime, Calendar calendar) {// 直接创建一个DatePickerDialog对话框实例,并将它显示出来new DatePickerDialog(activity, themeResId// 绑定监听器(How the parent is notified that the date is set.), new DatePickerDialog.OnDateSetListener() {private String times;@Overridepublic void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {// 此处得到选择的时间,可以进行你想要的操作times = year + "-" + (monthOfYear + 1) + "-" + dayOfMonth;tvTime.setText(times);}}// 设置初始日期, calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH), calendar.get(Calendar.DAY_OF_MONTH)).show();}

 

  相关解决方案