我使用API版本23创建基于警报的应用程序。但是TimePicker getCurrentMinute,getCurrentHour方法已弃用。哪种方法将取代这种方法?
修改
According to google documentation now we have to use getMinute() and getHour() method. But it's only working in api 23. what we have to do for other api?
答案 0 :(得分:42)
只需查看Android官方文档.. http://developer.android.com/reference/android/widget/TimePicker.html
它告诉你一切
public Integer getCurrentMinute ()
Added in API level 1
This method was deprecated in API level 23.
Use getMinute()
Returns
the current minute
和
public Integer getCurrentHour ()
Added in API level 1
This method was deprecated in API level 23.
Use getHour()
Returns
the current hour in the range (0-23)
Android提供API版本的运行时检查。 大多数情况下,在这种情况下,您需要运行
等案例if (Build.VERSION.SDK_INT >= 23 )
myTimePickerView.getHour();
else
myTimePickerView.getCurrentHour();
@see http://developer.android.com/reference/android/os/Build.VERSION.html
答案 1 :(得分:0)
代码运行得到编译并运行说 "完成构建并执行自..."
因为如果你使用getHour或getMinute,你必须把version.SDK if else语句(我试过但由于某种原因当时没有工作) 然而,增加了代码行和复杂性。