作者热门文章
- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我正在尝试使用 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" />
我在这里遗漏了什么吗?
最佳答案
好的,我知道现在是什么问题了。它没有正确地将 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/
我是一名优秀的程序员,十分优秀!