我正在使用 android 轮作为时间选择器并获取如下值
private void SetTime(Context activity, int hour, int minute) {
LayoutInflater inf = LayoutInflater.from(activity);
// layout of alert box contains
View view = inf.inflate(R.layout.wheel, null);
final WheelView hours = (WheelView) view.findViewById(R.id.hours);
hours.setViewAdapter(new NumericWheelAdapter(activity, 0, 23,"%02d"));
hours.setCyclic(true);
hours.setCurrentItem(expiryHour);
Log.d(TAG, "for expiryHour123456 ---> " + expiryHour);
final WheelView mins = (WheelView) view.findViewById(R.id.minutes);
mins.setViewAdapter(new Mywheel(activity, 0, 59,"%02d"));
mins.setCyclic(true);
mins.setCurrentItem(expiryMinute);
Log.d(TAG, "for expiryMinute123456 ---> " + expiryMinute);
new AlertDialog.Builder(activity)
.setMessage("Set Time For Post To AutoDelete")
.setView(view)
.setPositiveButton("Set",
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
expiryHour = hours.getCurrentItem();
Log.d(TAG, "for expiryHour ---> " + expiryHour);
if(mins.getCurrentItem() > 0){
expiryMinute = mins.getCurrentItem() + 4;
Log.d(TAG, "for expiryMinute ---> " + expiryMinute);
}else{
expiryMinute = mins.getCurrentItem();
}
}
});
}
当我设置时间时,我得到了正确的值,但是,如果我想更改时间一次又一次地设置时间,分钟值显示错误。例如,首先我将其设置为 2:10,然后当我打开它的显示 2:14 时我想现在进行更改,这不应该发生。感谢任何帮助。