Пример #1
0
        private void SetDefault()
        {
            var hourIndex = DateTime.Now.Hour - _hourStartIndex;

            // Set index corresponding to the current hour (index start at 0).
            _hoursSpinner.SetCurrentItem(hourIndex, true);

            // Get index corresponding to the current minute.
            var minuteIndex = (int)Math.Round((double)DateTime.Now.Minute / 15, 0);

            // Increment to get index of the next entry.
            minuteIndex++;

            // If no entry available for the current hour.
            if (minuteIndex > 3)
            {
                // Next available value is the following hour.
                minuteIndex = 0;
                hourIndex++;

                if (hourIndex > _hourLastIndex)
                {
                    hourIndex = 0;
                }

                _hoursSpinner.SetCurrentItem(hourIndex, true);
            }

            _minSpinner.SetCurrentItem(minuteIndex, true);

            // Set AM or PM
            _ampm.SetCurrentItem(DateTime.Now.Hour > 12 ? 1 : 0, true);
        }
Пример #2
0
        public void SetValue(DateTime value)
        {
            _daySpinner = (WheelVerticalView)FindViewById(Resource.Id.daySpinner);
            var index = ((DayArrayAdapter)_daySpinner.ViewAdapter).GetIndexFromValue(value);

            _daySpinner.SetCurrentItem(index, true);

            _hoursSpinner = (AbstractWheelView)FindViewById(Resource.Id.hourSpinner);
            _hoursSpinner.SetCurrentItem(value.Hour - _hourStartIndex, true);

            _minSpinner = (AbstractWheelView)FindViewById(Resource.Id.minSpinner);
            _minSpinner.SetCurrentItem(value.Minute / 15, true);

            _ampm = (AbstractWheelView)FindViewById(Resource.Id.ampmSpinner);
            _ampm.SetCurrentItem(value.Hour > 12 ? 1 : 0, true);

            if (!IsValid())
            {
                SetDefault();
            }
        }