如何从TimePicker获得的价值时间的Android [英] how to get the value time from TimePicker in Android
问题描述
我只是想从TimePicker得到小时和分钟,并显示它作为一个字符串,
比如我做timepicker 13:30,我想要得到的时刻13和13分钟为30分开。
I simply wanna get the hour and minute from TimePicker and display it as a string, for example I make the timepicker 13:30, and I wanna get the hour as 13 and minute as 30 seperately.
这就是所有我需要的。
我试过.getHour()和getMinute(),但这些方法让我当前的时间,我不需要。
I tried that .getHour() and getMinute() but these methods get me the current time which i dont need.
推荐答案
我不知道你现在在做什么。尝试为onTimeSet方法建立一个监听器。它有两个参数是正是你需要的。例如:
I'm not sure what you're doing right now. Try setting up a listener for the onTimeSet method. It has two parameters that are exactly what you need. For example:
创建TimePickerDialog:
Create a TimePickerDialog:
public void onClickSetEndTime(View v)
{
TimePickerDialog d = new TimePickerDialog(mActivity,
timeEndSetListener, timeEnd.get(Calendar.HOUR_OF_DAY),
timeEnd.get(Calendar.MINUTE), false);
d.show();
}
然后设置监听器。在我的情况下,它的timeEndSetListener。
Then setup the listener. In my case it's "timeEndSetListener".
private TimePickerDialog.OnTimeSetListener timeEndSetListener = new TimePickerDialog.OnTimeSetListener()
{
public void onTimeSet(TimePicker view, int hourOfDay, int minute)
{
// do what you need to do with the hour and minute
}
};
祝你好运。
这篇关于如何从TimePicker获得的价值时间的Android的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!