17

I want to show 24 hours clock instead 12 hours using TimePicker,and I dont need 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?

RobinHood
  • 10,464
  • 4
  • 44
  • 92
NullPointerException
  • 32,153
  • 66
  • 194
  • 346

4 Answers4

13

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:

alt text

Bryan Denny
  • 26,451
  • 32
  • 103
  • 124
  • i prefeer to use timepicker, i need bassically to call "setIs24HourView(true)" from the layout, not from the java code. it is possible? – NullPointerException Nov 10 '10 at 17:21
  • It doesn't seem possible, I can't find it in the documentation :/ – Bryan Denny Nov 10 '10 at 17:24
  • ouch well i will wait if someone know it – NullPointerException Nov 10 '10 at 17:30
  • (example link is dead...) Could you post how you did the double picker control separated by a decimal? That's pretty neat. – pmont Aug 16 '13 at 05:57
  • 1
    @pmont new link here: http://code.google.com/p/tippytipper/source/browse/trunk/Tippy%20Tipper%20Library/src/net/mandaria/tippytipperlibrary/preferences/DecimalPreference.java I recently migrated code into a library project. Will update answer too. – Bryan Denny Aug 16 '13 at 14:06
6

I've experienced the same problem but solved it by doing the setIs24HourView in the onCreate call for the activity..

Wh1T3h4Ck5
  • 8,045
  • 9
  • 52
  • 74
Hamzterman
  • 61
  • 1
  • 1
2

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);
Hossein
  • 314
  • 3
  • 12
0

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");
sasha.sochka
  • 12,899
  • 8
  • 41
  • 64