安卓:TimePicker setIs24HourView不工作 [英] Android: TimePicker setIs24HourView not working

查看:425
本文介绍了安卓:TimePicker setIs24HourView不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用TimePicker以24小时格式,我使用setIs24HourView =真实的,但我仍然没有得到24小时格式的TimePicker。这是我的code。在活动的onCreate。

I am trying to use the TimePicker in the 24 hour format and I am using setIs24HourView= true, but I am still not getting 24 hour format on the TimePicker. Here is my code in the onCreate of the Activity.

    timePicker = (TimePicker) findViewById(R.id.timePicker1);
    timePicker.setIs24HourView(true);

我甚至尝试timePicker.setCurrentHour(cal.HOUR_OF_DAY)setIs24HourView后,但我无法看到24小时格式的TimePicker。

I even tried timePicker.setCurrentHour(cal.HOUR_OF_DAY) after setIs24HourView, but I am not able to see the 24 hour format on the TimePicker.

<TimePicker
    android:id="@+id/timePicker1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginTop="110dp" />

我缺少什么吗?

Am I missing anything here?

推荐答案

好吧,我看是什么问题了。 这不是正确设置currentHour的到新的24小时格式,这就是为什么你得到了9:05,而不是21:05。我猜这是不是上午9时你在哪里! 它是一个错误,正如在此<一href="http://stackoverflow.com/questions/13662288/timepicker-hour-doesnt-update-after-switching-to-24h">question 似乎唯一的变通,就目前而言,就是做这样的事情:

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));

我看你试过cal.HOUR_OF_DAY,但没有提供code,你实际使用,但试试这个,看看它是否会有所帮助。

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.

这篇关于安卓:TimePicker setIs24HourView不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆