[英]Unable to change the android time picker mode 24hrs mode to AM_PM mode
我在这里使用timepicker Dialouge,但是由于某些我不了解的原因,我无法将time picker
的模式更改为AM_PM mode
我尝试了代码timepicker.setIs24HourView(false);
这是我的代码
onCreate(..){
button.onClickListe..(new...(){
showTimePickerDialog();
});}
public static class TimePickerFragment extends DialogFragment implements
TimePickerDialog.OnTimeSetListener {
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
// Use the current time as the default values for the picker
final Calendar c = Calendar.getInstance();
int hour = c.get(Calendar.HOUR_OF_DAY);
int minute = c.get(Calendar.MINUTE);
// Create a new instance of TimePickerDialog and return
return new TimePickerDialog(getActivity(), this, hour, minute,
true);
}
public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
view.setIs24HourView(false);//TODO not working <-------- This code is not working here
setTimeString(hourOfDay, minute, 0);
timeView.setText(timeString);
}
}
`private void showTimePickerDialog() {
DialogFragment newFragment = new TimePickerFragment();
newFragment.show(getFragmentManager(), "timePicker");
}`}
检查TimePickerDialog
构造函数中的最后一个参数是否为24小时格式,因此禁用24小时格式,并为最后一个参数传递false
值:
return new TimePickerDialog(getActivity(), this, hour, minute,false);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.