android.widget.NumberPicker.OnValueChangeListener Java Examples

The following examples show how to use android.widget.NumberPicker.OnValueChangeListener. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DigitPickerPreference.java    From AndroidMaterialPreferences with Apache License 2.0 6 votes vote down vote up
/**
 * 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;
        }

    };
}
 
Example #2
Source File: MainActivity.java    From CompoundViews with Apache License 2.0 6 votes vote down vote up
@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);
        }
    });
}
 
Example #3
Source File: FormatPickerDialog.java    From Android-Webcam with Apache License 2.0 6 votes vote down vote up
@Override
public void onStart() {
    super.onStart();
    setCancelable(false);

    numberPicker = (NumberPicker) getDialog().findViewById(R.id.number_picker);
    numberPicker.setDescendantFocusability(NumberPicker.FOCUS_BLOCK_DESCENDANTS);
    numberPicker.setDisplayedValues(values);
    numberPicker.setMinValue(getMinimumValue());
    numberPicker.setMaxValue(getMaximumValue());
    numberPicker.setValue(getInitialValue());
    numberPicker.setWrapSelectorWheel(false);
    numberPicker.setOnValueChangedListener(new OnValueChangeListener() {
        @Override public void onValueChange(NumberPicker picker, int oldVal, int newVal) {
            currentIndex = newVal;
        }
    });
}
 
Example #4
Source File: GosEditDeviceDelayActivity.java    From Gizwits-SmartBuld_Android with MIT License 5 votes vote down vote up
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));
			}
		});
	}
 
Example #5
Source File: NumberPickerPreference.java    From AndroidMaterialPreferences with Apache License 2.0 5 votes vote down vote up
/**
 * 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();
        }

    };
}
 
Example #6
Source File: TimeFragment.java    From SlideDateTimePicker with Apache License 2.0 5 votes vote down vote up
/**
 * 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());
            }
        });
    }
}
 
Example #7
Source File: TimeFragment.java    From SlideDayTimePicker with Apache License 2.0 5 votes vote down vote up
/**
 * 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());
            }
        });
    }
}
 
Example #8
Source File: DayFragment.java    From SlideDayTimePicker with Apache License 2.0 4 votes vote down vote up
/**
 * 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;
}
 
Example #9
Source File: PersianDatePicker.java    From Smartlab with Apache License 2.0 4 votes vote down vote up
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();
		}
	});
}