To set listener with Picker
, your activity must implement the picker interface listener. (Actually, your activity is not mandatory to implement the interface, you can also use anonymous inner method. Whatever works.)
So in your activity:
public class MainActivity extends Activity implements NumberPicker.OnValueChangeListener {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
NumberPicker np = (NumberPicker)findViewById(R.id.numberPicker1);
np.setMaxValue(99);
np.setMinValue(0);
np.setValue(50);
np.setOnValueChangedListener(this);
}
public void onValueChange(NumberPicker picker, int oldVal, int newVal) {
Toast.makeText(this, "change", Toast.LENGTH_SHORT).show();
}
}