Android 时间选择器中的问题
我在 android 时间选择器控件中遇到了一个奇怪的问题,当我尝试选择 12PM 时,它返回像 12AM 这样的值,我尝试了多种方法,但无法解决问题,并且它在其他时间(如 1)工作正常, 2等
代码片段如下 -
case TIME_DIALOG_ID:
// Time picker dialog generation
TimePickerDialog.OnTimeSetListener mTimeSetListener = new TimePickerDialog.OnTimeSetListener() {
public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
mhour = hourOfDay;
mminute = minute;
updatetime();
}
};
return new TimePickerDialog(this, mTimeSetListener, mhour, mminute,
false);
从时间选择器中获取小时和分钟值,我将其显示到textView中,如下所示 -
public void updatetime() {
textShowTime.setText(new StringBuilder().append(pad(mhour)).append(":")
.append(pad(mminute)));
}
private static String pad(int c) {
if (c >= 10)
return String.valueOf(c);
else
return "0" + String.valueOf(c);
}
最后我解析textView值以获取毫秒...... 但出现了上述问题。
请帮助我哪里出错或建议任何其他解决方案。 提前致谢。
I got a strange problem in android time picker control, when I trying to select 12PM it is returning the value like 12AM I tried in number of ways but I was unable to fix the problem and it is working fine for the other hours like 1,2, etc.
Code snippet as follows -
case TIME_DIALOG_ID:
// Time picker dialog generation
TimePickerDialog.OnTimeSetListener mTimeSetListener = new TimePickerDialog.OnTimeSetListener() {
public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
mhour = hourOfDay;
mminute = minute;
updatetime();
}
};
return new TimePickerDialog(this, mTimeSetListener, mhour, mminute,
false);
Taking the hours and minutes value from time-picker I shows it into textView as follows -
public void updatetime() {
textShowTime.setText(new StringBuilder().append(pad(mhour)).append(":")
.append(pad(mminute)));
}
private static String pad(int c) {
if (c >= 10)
return String.valueOf(c);
else
return "0" + String.valueOf(c);
}
And lastly I parse the textView value to getting the milliseconds......
But problem as described above are occur.
please help me where I do mistake or suggest any another solution for it.
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论