I found a solution to this problem: the Luigi Massa Gallerano solution does not call the listener for changes.
In addition to its method, you need to add a wrap method that swipes your finger up and down each time. This causes changeListener, although the former value is, of course, lost.
fun setNumberPickerValue(viewInteraction: ViewInteraction, value: Int) { viewInteraction.perform(setValue(value)) viewInteraction.perform(GeneralSwipeAction(Swipe.SLOW, GeneralLocation.TOP_CENTER, GeneralLocation.BOTTOM_CENTER, Press.FINGER)) SystemClock.sleep(50) viewInteraction.perform(GeneralSwipeAction(Swipe.SLOW, GeneralLocation.BOTTOM_CENTER, GeneralLocation.TOP_CENTER, Press.FINGER)) SystemClock.sleep(50) }
In the above example, NumberPicker and Kotlin are used, but in principle they are one and the same.
source share