Android: TimePicker setIs24HourView not working

做~自己de王妃 提交于 2019-12-05 07:53:20
ElefantPhace

ok, I see what the problem is now. It's not correctly setting the currentHour to the new 24 hour format, which is why you got 9:05 instead of 21:05. I'm guessing it isn't 9am where you are! It is a bug, as mentioned in this question seems the only work around, for now, is to do something like:

timePicker = (TimePicker) findViewById(R.id.timePicker1);
timePicker.setIs24HourView(true);
timePicker.setCurrentHour(Calendar.get(Calendar.HOUR_OF_DAY));

I see you tried cal.HOUR_OF_DAY, but didn't provide the code you actually used, but try this and see if it helps.

I notice this problem in jelly bean You can set the time to show in 24 hour view

    TimePicker picker = (TimePicker) findViewById(R.id.timePicker1);
    picker.setIs24HourView(true);
    Calendar calendar = Calendar.getInstance();

    int h = calendar.get(Calendar.HOUR_OF_DAY);
    int m = calendar.get(Calendar.MINUTE);

    picker.setCurrentHour(h);
    picker.setCurrentMinute(m);

You can just use the device settings and thus let the user make this decision;

 String clockType = android.provider.Settings.System.getString(context.getContentResolver(), android.provider.Settings.System.TIME_12_24);
Sammys

setting timePicker.setCurrentHour(Calendar.get(Calendar.HOUR_OF_DAY)) solved the problem

krguang
timePicker = (TimePicker) findViewById(R.id.timePicker1);

timePicker.setIs24HourView(true);

We need to add this:

Calendar calendar = Calendar.getInstance();

timePicker.setCurrentHour(calendar.get(calendar.HOUR_OF_DAY));
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!