public
Created

Sample code for back porting Android NumberPicker widget.

  • Download Gist
NumberPickerWrapper.java
Java
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
public abstract class NumberPickerWrapper {
 
static public NumberPickerWrapper createHolder(View view) {
NumberPickerWrapper numberPickerWrapper;
numberPickerWrapper = Build.VERSION.SDK_INT > 10 ? new NumberPickerWrapper_Sdk14()
: new NumberPickerWrapper_Sdk10();
 
numberPickerWrapper.setView(view);
return numberPickerWrapper;
}
 
public abstract void setView(View view);
 
public abstract void setRange(int start, int end);
 
public abstract void setValue(int value);
 
public abstract int getValue();
}
NumberPickerWrapper_Sdk10.java
Java
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
public class NumberPickerWrapper_Sdk10 extends NumberPickerWrapper {
 
private com.howaboutwe.ui.NumberPicker numberPicker;
 
@Override
public void setView(View view) {
numberPicker = (com.howaboutwe.ui.NumberPicker) view;
}
 
@Override
public void setRange(int start, int end) {
numberPicker.setRange(start, end);
}
 
@Override
public void setValue(int value) {
numberPicker.setCurrent(value);
}
 
@Override
public int getValue() {
return numberPicker.getCurrent();
}
}
NumberPickerWrapper_Sdk14.java
Java
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
public class NumberPickerWrapper_Sdk14 extends NumberPickerWrapper {
 
private android.widget.NumberPicker numberPicker;
 
@Override
public void setView(View view) {
numberPicker = (android.widget.NumberPicker) view;
}
 
@Override
public void setRange(int start, int end) {
numberPicker.setMinValue(start);
numberPicker.setMaxValue(end);
}
 
@Override
public void setValue(int value) {
numberPicker.setValue(value);
}
 
@Override
public int getValue() {
return numberPicker.getValue();
}
}

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.