I want to show 24 hours clock instead 12 hours using TimePicker,and I dont n开发者_StackOverflow社区eed the AM/PM buton, Simply want to show 24 hours clock.
Is this possible?
I used setIs24HourView(true)
but it is is not working.
Suggest me How can I show 24 hours clock?
Have you tried setting setIs24HourView?
If you just need use the NumberPicker widget in other abnormal ways:
There is a NumberPicker widget in Android, but it is a private API. This guy pulled out the code such that you can drop it into any project.
Here is an example of how I used it for tax rates:
I've experienced the same problem but solved it by doing the setIs24HourView
in the onCreate
call for the activity..
You must call setIs24HourView function and send true for that.
when time picker are in 24 mode AM/PM will be disappear.
TimePicker tpHourMin = (TimePicker) findViewById(R.id.timePicker);
tpHourMin.setIs24HourView(true);
You can overrite the
public void onTimeChanged (TimePicker view, int hourOfDay, int minute)
method of TimePickerDialog to completely remove AM/PM:
class MyTimePickerDialog extends TimePickerDialog {
MyTimePickerDialog(Context context, TimePickerDialog.OnTimeSetListener callBack, int hourOfDay, int minute, boolean is24HourView) {
super(context, callBack, hourOfDay, minute, is24HourView);
}
@Override
public void onTimeChanged (TimePicker view, int hourOfDay, int minute) {
// to prevent the dialog from changing the title which by default contains AM/PM
}
}
Here is how to use it
MyTimePickerDialog dialog = new MyTimePickerDialog(getActivity(), this, hour, minute,
true /*DateFormat.is24HourFormat(getActivity())*/);
dialog.setTitle("Set Time");
精彩评论