gpt4 book ai didi

安卓:TimePicker setIs24HourView 不工作

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:26:30 24 4
gpt4 key购买 nike

我正在尝试使用 24 小时格式的 TimePicker,我正在使用 setIs24HourView= true,但我仍然没有在 TimePicker 上获得 24 小时格式。这是我在 Activity 的 onCreate 中的代码。

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

我什至在 setIs24HourView 之后尝试了 timePicker.setCurrentHour(cal.HOUR_OF_DAY),但我无法在 TimePicker 上看到 24 小时格式。

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

我在这里遗漏了什么吗?

enter image description here

最佳答案

好的,我知道现在是什么问题了。它没有正确地将 currentHour 设置为新的 24 小时格式,这就是为什么你得到 9:05 而不是 21:05。我猜你现在不是早上 9 点!这是一个错误,如本 question 中所述目前看来,唯一的解决办法是做类似的事情:

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

我看到您尝试过 cal.HOUR_OF_DAY,但没有提供您实际使用的代码,但试试这个看看是否有帮助。

关于安卓:TimePicker setIs24HourView 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15150430/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com