0

我正在使用 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 时我想现在进行更改,这不应该发生。感谢任何帮助。

4

2 回答 2

0

请检查您的代码中的以下几行。

if(mins.getCurrentItem() > 0){
         expiryMinute = mins.getCurrentItem() + 4;
         Log.d(TAG, "for expiryMinute ---> " + expiryMinute);
}

这可能是问题的原因。增加 mins 值是否有任何具体原因?

于 2013-03-12T10:24:07.847 回答
0

解决了像这样设置分钟轮的值 mins.setCurrentItem(expiryMinute-4);

final WheelView mins = (WheelView) view.findViewById(R.id.minutes);
            mins.setViewAdapter(new Mywheel(activity, 0, 59,"%02d"));
            mins.setCyclic(true);
            if(expiryMinute!=0){
            mins.setCurrentItem(expiryMinute-4);
            }
于 2013-03-12T12:43:36.597 回答