使用edittext监听器在android中验证日期和时间
作者:互联网
我点击编辑文本时遇到问题,我想点击编辑文本时会弹出日期和时间选择器对话框.请帮帮我.
public void setstarttime()
{
startTimePicker = new TimePickerDialog(this, new TimePickerDialog.OnTimeSetListener() {
public void onTimeSet(TimePicker picker, int hourOfDay, int minute) {
//set selected time to calender
//@author om
startTimeCal.set(Calendar.MINUTE, minute);
startTimeCal.set(Calendar.HOUR, hourOfDay);
mStartTimeHour = hourOfDay;
mStartTimeMinute = minute;
String am_pm = (hourOfDay < 12) ? "AM" : "PM";
starttime.setText(CommonUtil.getFormattedTimeInString(startTimeCal.getTimeInMillis()) + " " + am_pm);
// timeValidation(TAG_STARTTIME);
}
}, mStartTimeHour, mStartTimeMinute, false);
startTimePicker.show();
}
解决方法:
您应该实现OnFocusChangeListener
EditText myEditText=......;
myEditText.setOnFocusChangeListener(new View.OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
if(hasFocus){
// SHOW YOUR DIALOG
}
}
});
标签:android,android-datepicker,android-timepicker 来源: https://codeday.me/bug/20190706/1396256.html