I extended the NumberPicker class, I overrided to the setOnValueChangedListener but when I debug the code and I click on the plus button of the numberpicker, it never pass in my breakpoint inside the method setOnValueChangedListener. Something is wrong?
@TargetApi(Build.VERSION_CODES.HONEYCOMB)//For backward-compability
public class NumberPickerCustom extends NumberPicker
{
private int clickNumber = 0;
public NumberPickerCustom(Context context) {
super(context);
}
public NumberPickerCustom(Context context, AttributeSet attrs) {
super(context, attrs);
processAttributeSet(attrs);
}
public NumberPickerCustom(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
processAttributeSet(attrs);
}
private void processAttributeSet(AttributeSet attrs) {
//This method reads the parameters given in the xml file and sets the properties according to it
this.setMinValue(attrs.getAttributeIntValue(null, "min", 0));
this.setMaxValue(attrs.getAttributeIntValue(null, "max", 0));
this.setValue(attrs.getAttributeIntValue(null, "value", 0));
}
@Override
public void setOnValueChangedListener(
OnValueChangeListener onValueChangedListener)
{
super.setOnValueChangedListener(onValueChangedListener);
if (onValueChangedListener==null)
{
onValueChangedListener = new OnValueChangeListener() {
@Override
public void onValueChange(NumberPicker picker, int oldVal, int newVal)
{
clickNumber++;
if (clickNumber>10)
{
clickNumber = -1000;
Toast.makeText(getContext(), "Clicca sul numero centrale per inserire direttamente un valore", Toast.LENGTH_SHORT).show();
}
}
};
}
}
}