当前位置: 首页>>代码示例>>Java>>正文


Java OnValueChangeListener类代码示例

本文整理汇总了Java中android.widget.NumberPicker.OnValueChangeListener的典型用法代码示例。如果您正苦于以下问题:Java OnValueChangeListener类的具体用法?Java OnValueChangeListener怎么用?Java OnValueChangeListener使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


OnValueChangeListener类属于android.widget.NumberPicker包,在下文中一共展示了OnValueChangeListener类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: createNumberPickerListener

import android.widget.NumberPicker.OnValueChangeListener; //导入依赖的package包/类
/**
 * Creates and returns a listener, which allows to observe the {@link NumberPicker} widgets,
 * which are used by the preference.
 *
 * @return The listener, which has been created, as an instance of the type {@link
 * OnValueChangeListener}
 */
private OnValueChangeListener createNumberPickerListener() {
    return new OnValueChangeListener() {

        @Override
        public void onValueChange(final android.widget.NumberPicker picker, final int oldValue,
                                  final int newValue) {
            int value = 0;

            for (int i = 0; i < numberPickers.length; i++) {
                int exponent = numberPickers.length - i - 1;
                value += numberPickers[i].getValue() * Math.pow(NUMERIC_SYTEM, exponent);
            }

            currentNumber = value;
        }

    };
}
 
开发者ID:michael-rapp,项目名称:AndroidMaterialPreferences,代码行数:26,代码来源:DigitPickerPreference.java

示例2: onCreate

import android.widget.NumberPicker.OnValueChangeListener; //导入依赖的package包/类
@Override protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    mFriendCountPicker = (NumberPicker) findViewById(R.id.friend_count);
    mFriendNameView = (FriendNameView) findViewById(R.id.friend_names);
    mCountFriendsButton = (Button) findViewById(R.id.count_friends_button);

    mFriendCountPicker.setMaxValue(10);
    mFriendCountPicker.setOnValueChangedListener(new OnValueChangeListener() {
        @Override public void onValueChange(NumberPicker picker, int oldVal, int newVal) {
            mFriendNameView.setFriendCount(newVal);
        }
    });

    mCountFriendsButton.setOnClickListener(new OnClickListener() {
        @Override public void onClick(View v) {
            List<String> names = mFriendNameView.getFriendNames();
            Intent i = new Intent(MainActivity.this, FriendCountActivity.class);
            i.putStringArrayListExtra("names", new ArrayList<String>(names));
            startActivity(i);
        }
    });
}
 
开发者ID:rharter,项目名称:CompoundViews,代码行数:25,代码来源:MainActivity.java

示例3: initEvent

import android.widget.NumberPicker.OnValueChangeListener; //导入依赖的package包/类
private void initEvent() {
		tvSave.setOnClickListener(this);
		tvSave.setClickable(false);
		tvBack.setOnClickListener(this);
//		mPick.setMaxValue(59);
		mPick.setMaxValue(60);
		mPick.setMinValue(1);
		mPick.setOnLongPressUpdateInterval(100);
		mPick.setDescendantFocusability(NumberPicker.FOCUS_BLOCK_DESCENDANTS);
		setNumberPickerDividerColor(mPick);

		if (countDownMinute == 0) {
			mPick.setValue(1);
			tvSave.setClickable(true);
			tvSave.setTextColor(getResources().getColor(R.color.text_blue));
		} else {
			mPick.setValue(countDownMinute);
		}

		mPick.setOnValueChangedListener(new OnValueChangeListener() {

			@Override
			public void onValueChange(NumberPicker picker, int oldVal, int newVal) {
				tvSave.setClickable(true);
				tvSave.setTextColor(getResources().getColor(R.color.text_blue));
			}
		});
	}
 
开发者ID:gizwits,项目名称:Gizwits-SmartBuld_Android,代码行数:29,代码来源:GosEditDeviceDelayActivity.java

示例4: createNumberPickerListener

import android.widget.NumberPicker.OnValueChangeListener; //导入依赖的package包/类
/**
 * Creates and returns a listener, which allows to observe the {@link NumberPicker}, which is
 * used by the preference.
 *
 * @return The listener, which has been created, as an {@link OnValueChangeListener}
 */
private OnValueChangeListener createNumberPickerListener() {
    return new OnValueChangeListener() {

        @Override
        public void onValueChange(final android.widget.NumberPicker numberPicker,
                                  final int oldValue, final int newValue) {
            numberPicker.setValue(newValue);
            currentIndex = getMinNumber() + newValue * getStepSize();
        }

    };
}
 
开发者ID:michael-rapp,项目名称:AndroidMaterialPreferences,代码行数:19,代码来源:NumberPickerPreference.java

示例5: fixTimePickerBug18982

import android.widget.NumberPicker.OnValueChangeListener; //导入依赖的package包/类
/**
 * Workaround for bug in Android TimePicker where the onTimeChanged() callback
 * is not invoked when the user toggles between AM/PM. But we need to be able
 * to detect this in order to dynamically update the tab title properly when
 * the user toggles between AM/PM.
 *
 * Registered as Issue 18982:
 *
 * https://code.google.com/p/android/issues/detail?id=18982
 */
private void fixTimePickerBug18982()
{
    View amPmView = ((ViewGroup) mTimePicker.getChildAt(0)).getChildAt(3);

    if (amPmView instanceof NumberPicker)
    {
        ((NumberPicker) amPmView).setOnValueChangedListener(new OnValueChangeListener() {

            @Override
            public void onValueChange(NumberPicker picker, int oldVal, int newVal)
            {
                if (picker.getValue() == 1)  // PM
                {
                    if (mTimePicker.getCurrentHour() < 12)
                        mTimePicker.setCurrentHour(mTimePicker.getCurrentHour() + 12);
                }
                else  // AM
                {
                    if (mTimePicker.getCurrentHour() >= 12)
                        mTimePicker.setCurrentHour(mTimePicker.getCurrentHour() - 12);
                }

                mCallback.onTimeChanged(
                    mTimePicker.getCurrentHour(),
                    mTimePicker.getCurrentMinute());
            }
        });
    }
}
 
开发者ID:jjobes,项目名称:SlideDateTimePicker,代码行数:40,代码来源:TimeFragment.java

示例6: initialize

import android.widget.NumberPicker.OnValueChangeListener; //导入依赖的package包/类
public void initialize(ListPreference timer, ListPreference beep) {
    mTimer = timer;
    mBeep = beep;
    // Set title.
    mTitle.setText(mTimer.getTitle());

    // Duration
    CharSequence[] entries = mTimer.getEntryValues();
    mDurations = new String[entries.length];
    Locale locale = getResources().getConfiguration().locale;
    mDurations[0] = getResources().getString(R.string.setting_off); // Off
    for (int i = 1; i < entries.length; i++)
        mDurations[i] =  String.format(locale, "%d", Integer.parseInt(entries[i].toString()));
    int durationCount = mDurations.length;
    mNumberSpinner = (NumberPicker) findViewById(R.id.duration);
    mNumberSpinner.setMinValue(0);
    mNumberSpinner.setMaxValue(durationCount - 1);
    mNumberSpinner.setDisplayedValues(mDurations);
    mNumberSpinner.setWrapSelectorWheel(false);
    mNumberSpinner.setOnValueChangedListener(new OnValueChangeListener() {
        @Override
        public void onValueChange(NumberPicker picker, int oldValue, int newValue) {
            setTimeSelectionEnabled(newValue != 0);
        }
    });
    mConfirmButton = (Button) findViewById(R.id.timer_set_button);
    mPickerTitle = findViewById(R.id.set_time_interval_title);

    // Disable focus on the spinners to prevent keyboard from coming up
    mNumberSpinner.setDescendantFocusability(NumberPicker.FOCUS_BLOCK_DESCENDANTS);

    mConfirmButton.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            updateInputState();
        }
    });
    mTimerSound = (CheckBox) findViewById(R.id.sound_check_box);
    mSoundTitle = findViewById(R.id.beep_title);
}
 
开发者ID:asm-products,项目名称:nexus-camera,代码行数:40,代码来源:CountdownTimerPopup.java

示例7: onCreateDialog

import android.widget.NumberPicker.OnValueChangeListener; //导入依赖的package包/类
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {

	mCurNumber = getArguments().getInt(CUR_NUMBER);
	mMaxNumber = getArguments().getInt(MAX_NUMBER);
	mMinNumber = getArguments().getInt(MIN_NUMBER);

	View v = getActivity().getLayoutInflater().inflate(
			R.layout.dialog_number, null);

	NumberPicker numberPicker = (NumberPicker) v
			.findViewById(R.id.dialog_number_numberPicker);
	numberPicker.setMinValue(mMinNumber);
	numberPicker.setMaxValue(mMaxNumber);
	numberPicker.setValue(mCurNumber);
	numberPicker.setOnValueChangedListener(new OnValueChangeListener() {

		@Override
		public void onValueChange(NumberPicker picker, int oldVal,
				int newVal) {
			mCurNumber = picker.getValue();
			getArguments().putInt(CUR_NUMBER, mCurNumber);

		}
	});

	return new AlertDialog.Builder(getActivity())
			.setView(v)
			.setTitle(R.string.string_set_new_critical_level)
			.setPositiveButton(android.R.string.ok,
					new DialogInterface.OnClickListener() {

						@Override
						public void onClick(DialogInterface dialog,
								int which) {
							sendResult();

						}
					}).create();
}
 
开发者ID:nikablaine,项目名称:BatteryAlarm,代码行数:41,代码来源:NumberPickerFragment.java

示例8: onCreateView

import android.widget.NumberPicker.OnValueChangeListener; //导入依赖的package包/类
/**
 * Create and return the user interface view for this fragment.
 */
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
    int initialDay = getArguments().getInt("initialDay");
    boolean isCustomDaysArraySpecified = getArguments().getBoolean("isCustomDaysArraySpecified");

    String[] daysArray;
    if (isCustomDaysArraySpecified)
    {
        daysArray = getArguments().getStringArray("customDaysArray");
    }
    else
    {
        daysArray = getResources().getStringArray(R.array.days_array);
    }

    // Unless we inflate using a cloned inflater with a Holo theme,
    // on Lollipop devices the TimePicker will be the new-style
    // radial TimePicker, which is not what we want. So we will
    // clone the inflater that we're given but with our specified
    // theme, then inflate the layout with this new inflater.
    int theme = getArguments().getInt("theme");

    Context contextThemeWrapper = new ContextThemeWrapper(
            getActivity(),
            theme == SlideDayTimePicker.HOLO_DARK ?
                    android.R.style.Theme_Holo : android.R.style.Theme_Holo_Light);

    LayoutInflater localInflater = inflater.cloneInContext(contextThemeWrapper);

    View v = localInflater.inflate(R.layout.fragment_day, container, false);

    CustomNumberPicker dayPicker = (CustomNumberPicker) v.findViewById(R.id.dayPicker);
    // remove blinking cursor from NumberPicker
    enableNumberPickerEditing(dayPicker, false);
    // block keyboard popping up on touch
    dayPicker.setDescendantFocusability(NumberPicker.FOCUS_BLOCK_DESCENDANTS);
    dayPicker.setMinValue(0);
    dayPicker.setMaxValue(daysArray.length - 1);
    dayPicker.setDisplayedValues(daysArray);
    dayPicker.setValue(initialDay);
    dayPicker.setOnValueChangedListener(new OnValueChangeListener() {

        @Override
        public void onValueChange(NumberPicker picker, int oldVal, int newVal)
        {
            mCallback.onDayChanged(newVal);
        }
    });

    return v;
}
 
开发者ID:jjobes,项目名称:SlideDayTimePicker,代码行数:56,代码来源:DayFragment.java

示例9: PersianDatePicker

import android.widget.NumberPicker.OnValueChangeListener; //导入依赖的package包/类
public PersianDatePicker(final Context context, AttributeSet attrs, int defStyle) {
	super(context, attrs, defStyle);

	LayoutInflater inflater = (LayoutInflater) context
			.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
	View root = inflater.inflate(R.layout.pdp, this);
	yearNumberPicker = (NumberPicker) root
			.findViewById(R.id.yearNumberPicker);
	monthNumberPicker = (NumberPicker) root
			.findViewById(R.id.monthNumberPicker);
	dayNumberPicker = (NumberPicker) root
			.findViewById(R.id.dayNumberPicker);

	TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.PersianDatePicker, 0, 0);
	int year = 1393,month=6,day=19;
	
	year = a.getInteger(R.styleable.PersianDatePicker_year, 1393);
	month = a.getInteger(R.styleable.PersianDatePicker_month, 6);
	day = a.getInteger(R.styleable.PersianDatePicker_day, 19);
	
	a.recycle();

	yearNumberPicker.setMinValue(1380);
	yearNumberPicker.setMaxValue(1400);
	yearNumberPicker.setValue(year);

	monthNumberPicker.setMinValue(1);
	monthNumberPicker.setMaxValue(12);
	monthNumberPicker.setValue(month);

	dayNumberPicker.setMaxValue(31);
	dayNumberPicker.setMinValue(1);
	dayNumberPicker.setValue(day);
	
	yearNumberPicker.setOnValueChangedListener(new OnValueChangeListener() {
		
		@Override
		public void onValueChange(NumberPicker np, int oldValue, int newValue) {
			Toast.makeText(context, "Year changed:" + oldValue + " -> " + newValue, Toast.LENGTH_LONG).show();
		}
	});
}
 
开发者ID:alibehzadian,项目名称:Smartlab,代码行数:43,代码来源:PersianDatePicker.java

示例10: onCreate

import android.widget.NumberPicker.OnValueChangeListener; //导入依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);
	setContentView(R.layout.activity_log);
	getActionBar().setDisplayHomeAsUpEnabled(true);
	
	SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(this);
       boolean keepScreenOnSetting = settings.getBoolean("screenOn", true);
       
       if(keepScreenOnSetting) {
       	getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
       	Log.i("SETTINGS", "Keeping screen on, per request");
       } else {
       	Log.i("SETTINGS", "Not keeping screen on");
       }
       
       this.metric = settings.getBoolean("metricUnits", false);
       this.weightScale = metric ? 1 : 5;
       
	currentLogs = new ArrayList<LogEntry>();
	previousLogs = new ArrayList<LogEntry>();
	
	currentExercise = (Exercise) getIntent().getExtras().getSerializable("exercise");

	TextView weightPickerLabel = (TextView) findViewById(R.id.weightPickerLabel);
	weightPickerLabel.setText(getResources().getString( metric ? R.string.weightPickerLabelMetric : R.string.weightPickerLabelImperial));
	
	NumberPicker weightPicker = (NumberPicker) findViewById(R.id.weightPicker);
	weightPicker.setDescendantFocusability(NumberPicker.FOCUS_BLOCK_DESCENDANTS);

	String[] displayedValues = new String[NUM_WEIGHT_VALUES];
	//String weightUnits = metric ? "kg" : "lbs";
	// Populate the array
	for (int i = 0; i < NUM_WEIGHT_VALUES; i++) 
		displayedValues[i] = String.valueOf(weightScale * (i + 1));

	weightPicker.setMinValue(0);
	weightPicker.setMaxValue(displayedValues.length - 1);
	weightPicker.setDisplayedValues(displayedValues);
	weightPicker.setWrapSelectorWheel(false);

	NumberPicker repsPicker = (NumberPicker) findViewById(R.id.repsPicker);
	repsPicker.setDescendantFocusability(NumberPicker.FOCUS_BLOCK_DESCENDANTS);
	String[] displayedReps = new String[NUM_REP_VALUES];
	// Populate the array
	for (int i = 0; i < NUM_REP_VALUES; i++)
		displayedReps[i] = (i + 1)+"";

	repsPicker.setMinValue(0);
	repsPicker.setMaxValue(displayedReps.length - 1);
	repsPicker.setDisplayedValues(displayedReps);
	repsPicker.setWrapSelectorWheel(false);

	OnValueChangeListener onValueChangeListener = new OnValueChangeListener() {

		@Override
		public void onValueChange(NumberPicker arg0, int arg1, int arg2) {
			showCurrentLogs();
		}

	};
	weightPicker.setOnValueChangedListener(onValueChangeListener);
	repsPicker.setOnValueChangedListener(onValueChangeListener);

	if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
		ActionBar ab = getActionBar();
		ab.setTitle(currentExercise.name);
		if(currentExercise.muscles != null && currentExercise.muscles.length > 0) {
			ab.setSubtitle(Util.join(currentExercise.muscles, ", ", null));
		}
	}
	
	File dir = Util.getLogStorageDir(getApplicationContext());
	
	findViewById(R.id.buttonBar).setVisibility(View.INVISIBLE);
	findViewById(R.id.currentLogsLayout).setVisibility(View.INVISIBLE);
	findViewById(R.id.previousLogsLayout).setVisibility(View.INVISIBLE);
	findViewById(R.id.logLoadProgress).setVisibility(View.VISIBLE);
	
	new LoadLogData(this, currentExercise, dir).execute();
}
 
开发者ID:rodhilton,项目名称:SimpleStrengthLog,代码行数:82,代码来源:LogActivity.java

示例11: TwoFieldDatePicker

import android.widget.NumberPicker.OnValueChangeListener; //导入依赖的package包/类
public TwoFieldDatePicker(Context context, long minValue, long maxValue) {
    super(context, null, android.R.attr.datePickerStyle);

    LayoutInflater inflater = (LayoutInflater) context
            .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    inflater.inflate(R.layout.two_field_date_picker, this, true);

    OnValueChangeListener onChangeListener = new OnValueChangeListener() {
        @Override
        public void onValueChange(NumberPicker picker, int oldVal, int newVal) {
            int year = getYear();
            int positionInYear = getPositionInYear();
            // take care of wrapping of days and months to update greater fields
            if (picker == mPositionInYearSpinner) {
                positionInYear = newVal;
                if (oldVal == picker.getMaxValue() && newVal == picker.getMinValue()) {
                    year += 1;
                } else if (oldVal == picker.getMinValue() && newVal == picker.getMaxValue()) {
                    year -=1;
                }
            } else if (picker == mYearSpinner) {
                year = newVal;
             } else {
                throw new IllegalArgumentException();
            }

            // now set the date to the adjusted one
            setCurrentDate(year, positionInYear);
            updateSpinners();
            notifyDateChanged();
        }
    };

    mCurrentDate = Calendar.getInstance();
    if (minValue >= maxValue) {
        mMinDate = Calendar.getInstance();
        mMinDate.set(0, 0, 1);
        mMaxDate = Calendar.getInstance();
        mMaxDate.set(9999, 0, 1);
    } else {
        mMinDate = createDateFromValue(minValue);
        mMaxDate = createDateFromValue(maxValue);
    }

    // month
    mPositionInYearSpinner = (NumberPicker) findViewById(R.id.position_in_year);
    mPositionInYearSpinner.setOnLongPressUpdateInterval(200);
    mPositionInYearSpinner.setOnValueChangedListener(onChangeListener);

    // year
    mYearSpinner = (NumberPicker) findViewById(R.id.year);
    mYearSpinner.setOnLongPressUpdateInterval(100);
    mYearSpinner.setOnValueChangedListener(onChangeListener);
}
 
开发者ID:openresearch,项目名称:android-chromium-view,代码行数:55,代码来源:TwoFieldDatePicker.java

示例12: onCreate

import android.widget.NumberPicker.OnValueChangeListener; //导入依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);
	setContentView(R.layout.activity_log);
	// Show the Up button in the action bar.
	getActionBar().setDisplayHomeAsUpEnabled(true);
	ActionBar ab = getActionBar();

	// Application State Setup
	currentExercise = (Exercise) getIntent().getExtras().getSerializable("exercise");
	logs = new HashMap<LocalDate, List<LogEntry>>();

	ab.setTitle(currentExercise.name);

	if (savedInstanceState != null && savedInstanceState.containsKey("ManuallySelectedCals")) {
		manuallySelectedCals = savedInstanceState.getBoolean("ManuallySelectedCals");
	} else {
		manuallySelectedCals = false;
	}

	NumberPicker minutesPicker = (NumberPicker) findViewById(R.id.minutesPicker);
	setPickerRange(minutesPicker, 1, MINUTES_MAX, 1, BigDecimal.ONE);
	minutesPicker.setOnValueChangedListener(this);

	if (currentExercise.isUnitless()) {
		findViewById(R.id.unitSelection).setVisibility(View.GONE);
		minutesPicker.setOnScrollListener(this);
	} else {
		findViewById(R.id.unitSelection).setVisibility(View.VISIBLE);

		TextView unitTextView = (TextView) findViewById(R.id.unitTextView);
		unitTextView.setText(currentExercise.units);

		NumberPicker unitPicker = (NumberPicker) findViewById(R.id.unitPicker);
		BigDecimal increment = new BigDecimal(currentExercise.precision);
		setPickerRange(unitPicker, 1, UNIT_MAX, 1, increment);
		unitPicker.setOnValueChangedListener(this);
		unitPicker.setOnScrollListener(this);
	}

	NumberPicker caloriesPicker = (NumberPicker) findViewById(R.id.caloriesPicker);
	setPickerRange(caloriesPicker, 1, CALORIE_MAX, 1, CALORIE_INCREMENT);
	caloriesPicker.setOnValueChangedListener(new OnValueChangeListener() {

		@Override
		public void onValueChange(NumberPicker arg0, int arg1, int arg2) {
			manuallySelectedCals = true;
			showCurrentLogs();
		}

	});

	findViewById(R.id.saveButton).setOnClickListener(this);
	findViewById(R.id.undoButton).setOnClickListener(this);

	findViewById(R.id.buttonBar).setVisibility(View.INVISIBLE);
	findViewById(R.id.logsScroll).setVisibility(View.INVISIBLE);
	findViewById(R.id.logLoadProgress).setVisibility(View.VISIBLE);

	new LoadLogData(this, currentExercise, Util.getLogStorageDir(getApplicationContext()), MAX_REGRESSION_POINTS).execute();
}
 
开发者ID:rodhilton,项目名称:SimpleCardioLog,代码行数:62,代码来源:LogActivity.java

示例13: TwoFieldDatePicker

import android.widget.NumberPicker.OnValueChangeListener; //导入依赖的package包/类
public TwoFieldDatePicker(Context context, long minValue, long maxValue) {
    super(context, null, android.R.attr.datePickerStyle);

    LayoutInflater inflater = (LayoutInflater) context
            .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    inflater.inflate(R.layout.two_field_date_picker, this, true);

    OnValueChangeListener onChangeListener = new OnValueChangeListener() {
        @Override
        public void onValueChange(NumberPicker picker, int oldVal, int newVal) {
            int year = getYear();
            int positionInYear = getPositionInYear();
            // take care of wrapping of days and months to update greater fields
            if (picker == mPositionInYearSpinner) {
                positionInYear = newVal;
                if (oldVal == picker.getMaxValue() && newVal == picker.getMinValue()) {
                    year += 1;
                    positionInYear = getMinPositionInYear(year);
                } else if (oldVal == picker.getMinValue() && newVal == picker.getMaxValue()) {
                    year -=1;
                    positionInYear = getMaxPositionInYear(year);
                }
            } else if (picker == mYearSpinner) {
                year = newVal;
             } else {
                throw new IllegalArgumentException();
            }

            // now set the date to the adjusted one
            setCurrentDate(year, positionInYear);
            updateSpinners();
            notifyDateChanged();
        }
    };

    mCurrentDate = Calendar.getInstance();
    if (minValue >= maxValue) {
        mMinDate = Calendar.getInstance();
        mMinDate.set(0, 0, 1);
        mMaxDate = Calendar.getInstance();
        mMaxDate.set(9999, 0, 1);
    } else {
        mMinDate = createDateFromValue(minValue);
        mMaxDate = createDateFromValue(maxValue);
    }

    // month
    mPositionInYearSpinner = (NumberPicker) findViewById(R.id.position_in_year);
    mPositionInYearSpinner.setOnLongPressUpdateInterval(200);
    mPositionInYearSpinner.setOnValueChangedListener(onChangeListener);

    // year
    mYearSpinner = (NumberPicker) findViewById(R.id.year);
    mYearSpinner.setOnLongPressUpdateInterval(100);
    mYearSpinner.setOnValueChangedListener(onChangeListener);
}
 
开发者ID:morristech,项目名称:android-chromium,代码行数:57,代码来源:TwoFieldDatePicker.java

示例14: TwoFieldDatePicker

import android.widget.NumberPicker.OnValueChangeListener; //导入依赖的package包/类
public TwoFieldDatePicker(Context context, double minValue, double maxValue) {
    super(context, null, android.R.attr.datePickerStyle);

    LayoutInflater inflater = (LayoutInflater) context
            .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    inflater.inflate(R.layout.two_field_date_picker, this, true);

    OnValueChangeListener onChangeListener = new OnValueChangeListener() {
        @Override
        public void onValueChange(NumberPicker picker, int oldVal, int newVal) {
            int year = getYear();
            int positionInYear = getPositionInYear();
            // take care of wrapping of days and months to update greater fields
            if (picker == mPositionInYearSpinner) {
                positionInYear = newVal;
                if (oldVal == picker.getMaxValue() && newVal == picker.getMinValue()) {
                    year += 1;
                    positionInYear = getMinPositionInYear(year);
                } else if (oldVal == picker.getMinValue() && newVal == picker.getMaxValue()) {
                    year -= 1;
                    positionInYear = getMaxPositionInYear(year);
                }
            } else if (picker == mYearSpinner) {
                year = newVal;
            } else {
                throw new IllegalArgumentException();
            }

            // now set the date to the adjusted one
            setCurrentDate(year, positionInYear);
            updateSpinners();
            notifyDateChanged();
        }
    };

    mCurrentDate = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
    if (minValue >= maxValue) {
        mMinDate = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
        mMinDate.set(0, 0, 1);
        mMaxDate = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
        mMaxDate.set(9999, 0, 1);
    } else {
        mMinDate = getDateForValue(minValue);
        mMaxDate = getDateForValue(maxValue);
    }

    // month
    mPositionInYearSpinner = (NumberPicker) findViewById(R.id.position_in_year);
    mPositionInYearSpinner.setOnLongPressUpdateInterval(200);
    mPositionInYearSpinner.setOnValueChangedListener(onChangeListener);

    // year
    mYearSpinner = (NumberPicker) findViewById(R.id.year);
    mYearSpinner.setOnLongPressUpdateInterval(100);
    mYearSpinner.setOnValueChangedListener(onChangeListener);
}
 
开发者ID:mogoweb,项目名称:chromium_webview,代码行数:57,代码来源:TwoFieldDatePicker.java


注:本文中的android.widget.NumberPicker.OnValueChangeListener类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。