Search code examples
androidandroid-eventandroid-number-picker

NumberPicker, OnValueChangedListener, distinguish change from user and from programmatic change?


It seems that OnValueChangedListener is called when the value is changed programmatically by the app itself. Can I make it raised only when the user rotates the dial or know whether the event is from the app (code) or from the user?


Solution

  • You could have a field holding the pickers current value. If you want to set the current number of the picker from your code, change the field before updating the number picker. In the pickers listener, simply ignore events where the new number is already equal to the field. Otherwise handle the change and update the field.