记录过一篇DatePickerDialog的博客好看的DatePickerDialog非常简单的实现,用于选择年月日。这次记录一下TimePickerDialog,大体上和DatePickerDialog相同,附上效果图:
同样是一个editText单击后弹出
代码如下:
etCheckTime.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View view) {// 此处为得到焦点时的处理内容Calendar c = Calendar.getInstance();// 创建一个TimePickerDialog实例,并把它显示出来// 设置初始时间// true表示采用24小时制new TimePickerDialog(mContext, new TimePickerDialog.OnTimeSetListener() {@Overridepublic void onTimeSet(TimePicker timePicker, int hourOfDay, int minute) {viewHolder.etCheckTime.setText(hourOfDay + ":" + minute);viewHolder.etCheckTime.requestFocus();}}, c.get(Calendar.HOUR_OF_DAY), c.get(Calendar.MINUTE), true).show();}});