在一些低版本的手机中使用时间监听会出现
NoSuchMethodError
timepickerChoose.setOnDateChangedListener(new DatePicker.OnDateChangedListener() {
@SuppressLint("SetTextI18n")
@Override
public void onDateChanged(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
}
});
解决办法
捕捉异常,在catch语句块里面写入
DatePicker datePicker = (DatePicker) findViewById(R.id.datePicker);
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(System.currentTimeMillis());
datePicker.init(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH), calendar.get(Calendar.DAY_OF_MONTH), new DatePicker.OnDateChangedListener() {
@Override
public void onDateChanged(DatePicker datePicker, int year, int month, int dayOfMonth) {
Log.d("Date", "Year=" + year + " Month=" + (month + 1) + " day=" + dayOfMonth);
}
});