Skip to content

Instantly share code, notes, and snippets.

@ecgreb
Created January 2, 2013 21:54
Show Gist options
  • Save ecgreb/4438510 to your computer and use it in GitHub Desktop.
Save ecgreb/4438510 to your computer and use it in GitHub Desktop.
Sample code for back porting Android NumberPicker widget.
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();
}
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();
}
}
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();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment