Android NumberPicker - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Android NumberPicker class.

This code example shows how to use the following methods:getMaxValue, getMinValue, setDisplayedValues, setMaxValue, setMinValue
8
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:setDisplayedValues, setMaxValue, setMinValue, setValue, setWrapSelectorWheel
 
    /** 
     * This method should be subclassed to update the spinners based on mCurrentDate. 
     */ 
    protected void updateSpinners() { 
        mPositionInYearSpinner.setDisplayedValues(null);
 
        // set the spinner ranges respecting the min and max dates 
        mPositionInYearSpinner.setMinValue(getMinPositionInYear());
        mPositionInYearSpinner.setMaxValue(getMaxPositionInYear());
        mPositionInYearSpinner.setWrapSelectorWheel(
                !mCurrentDate.equals(mMinDate) && !mCurrentDate.equals(mMaxDate));
 
        // year spinner range does not change based on the current date 
        mYearSpinner.setMinValue(getMinYear());
        mYearSpinner.setMaxValue(getMaxYear());
        mYearSpinner.setWrapSelectorWheel(false);
 
        // set the spinner values 
        mYearSpinner.setValue(getYear());

7
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:clearFocus, getValue
        mNumberPicker.setValue(number);
    } 
 
    public void onClick(DialogInterface dialog, int which) {
        if (mCallback != null) {
            mNumberPicker.clearFocus();
            mCallback.onNumberSet(mDialogId, mNumberPicker.getValue());
            dialog.dismiss();
        } 
    } 
 
    @Override 
    public Bundle onSaveInstanceState() {
        Bundle state = super.onSaveInstanceState();
        state.putInt(NUMBER, mNumberPicker.getValue());
        return state;
    } 
 
    @Override 
    public void onRestoreInstanceState(Bundle savedInstanceState) {
8
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:getMaxValue, getMinValue, setDisplayedValues, setMaxValue, setMinValue
            mMonthSpinner.setDisplayedValues(null);
            mMonthSpinner.setMinValue(mCurrentDate.getActualMinimum(Calendar.MONTH));
            mMonthSpinner.setMaxValue(mCurrentDate.get(Calendar.MONTH));
            mMonthSpinner.setWrapSelectorWheel(false);
        } else { 
            mMonthSpinner.setDisplayedValues(null);
            mMonthSpinner.setMinValue(0);
            mMonthSpinner.setMaxValue(11);
            mMonthSpinner.setWrapSelectorWheel(true);
        } 
 
        // make sure the month names are a zero based array 
        // with the months in the month spinner 
        String[] displayedValues = Arrays.copyOfRange(mShortMonths,
                mMonthSpinner.getMinValue(), mMonthSpinner.getMaxValue() + 1);
        mMonthSpinner.setDisplayedValues(displayedValues);
 
        // year spinner range does not change based on the current date 
        mYearSpinner.setMinValue(mMinDate.get(Calendar.YEAR));
        mYearSpinner.setMaxValue(mMaxDate.get(Calendar.YEAR));
6
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:getMaxValue, getValue
    public void reloadPreference() { 
    } 
 
    private void updateInputState() { 
        if (mTimeLapseSwitch.isChecked()) {
            int newId = mUnitSpinner.getValue() * (mNumberSpinner.getMaxValue() + 1)
                    + mNumberSpinner.getValue() + 1;
            mPreference.setValueIndex(newId);
        } else { 
            mPreference.setValueIndex(0);
        } 
 
        if (mListener != null) {
            mListener.onListPrefChanged(mPreference);
        } 
    } 
} 
6
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:setFocusable, setFocusableInTouchMode, setLayoutParams, setFormatter, setMaxValue
     * @return NumberPicker The that represents the number picker 
     */ 
    private NumberPicker createNumberPicker(
            int maxValue, TextView toAlignWith, TextView toHeightOf, final String format) {
        // Create the NumberPicker 
        NumberPicker digit = new NumberPicker(getContext());
        LayoutParams params = new RelativeLayout.LayoutParams(
                android.view.ViewGroup.LayoutParams.WRAP_CONTENT,
                android.view.ViewGroup.LayoutParams.WRAP_CONTENT);
        params.addRule(RelativeLayout.ALIGN_LEFT, toAlignWith.getId());
        params.addRule(RelativeLayout.ALIGN_RIGHT, toAlignWith.getId());
        params.addRule(RelativeLayout.ALIGN_TOP, toHeightOf.getId());
        params.addRule(RelativeLayout.ALIGN_BOTTOM, toHeightOf.getId());
        digit.setLayoutParams(params);
        digit.setMinValue(0);
        digit.setMaxValue(maxValue);
        digit.setValue(0);
        digit.setWrapSelectorWheel(false);
        digit.setFocusable(false);
        digit.setFocusableInTouchMode(false);

6
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:setVisibility, setCurrent
    private void updateSpinners() { 
        updateDaySpinner(); 
 
        mYearToggle.setChecked(mHasYear);
        mYearToggle.setVisibility(mYearOptional ? View.VISIBLE : View.GONE);
        mYearPicker.setCurrent(mYear);
        mYearPicker.setVisibility(mHasYear ? View.VISIBLE : View.GONE);
 
        /* The month display uses 1-12 but our internal state stores it 
         * 0-11 so add one when setting the display. 
         */ 
        mMonthPicker.setCurrent(mMonth + 1);
    } 
 
    private void updateDaySpinner() { 
        Calendar cal = Calendar.getInstance();
        // if year was not set, use 2000 as it was a leap year 
        cal.set(mHasYear ? mYear : 2000, mMonth, 1);
        int max = cal.getActualMaximum(Calendar.DAY_OF_MONTH);
        mDayPicker.setRange(1, max);
6
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:setFocusable, setFocusableInTouchMode, clearFocus, hasFocus, getValue
6
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:getValue
    } 
 
    @Override 
    protected void onDialogClosed(boolean positiveResult) {
        if (positiveResult) {
            persistInt(mNumberPicker.getValue());
        } 
    } 
 
} 
6
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:setDisplayedValues, setMaxValue, setMinValue, setValue, setWrapSelectorWheel
 
    /** 
     * This method should be subclassed to update the spinners based on mCurrentDate. 
     */ 
    protected void updateSpinners() { 
        mPositionInYearSpinner.setDisplayedValues(null);
 
        // set the spinner ranges respecting the min and max dates 
        mPositionInYearSpinner.setMinValue(getMinPositionInYear());
        mPositionInYearSpinner.setMaxValue(getMaxPositionInYear());
        mPositionInYearSpinner.setWrapSelectorWheel(
                !mCurrentDate.equals(mMinDate) && !mCurrentDate.equals(mMaxDate));
 
        // year spinner range does not change based on the current date 
        mYearSpinner.setMinValue(getMinYear());
        mYearSpinner.setMaxValue(getMaxYear());
        mYearSpinner.setWrapSelectorWheel(false);
 
        // set the spinner values 
        mYearSpinner.setValue(getYear());

6
CodeRank
Connect your IDE to all the code out there  Get Codota for Java

Related Android NumberPicker Questions & Answers:

See Code Examples for Android NumberPicker Methods: