Skip to content

Instantly share code, notes, and snippets.

@Regenhardt
Last active August 29, 2015 14:17
Show Gist options
  • Save Regenhardt/73fe9e679985ec3d7dda to your computer and use it in GitHub Desktop.
Save Regenhardt/73fe9e679985ec3d7dda to your computer and use it in GitHub Desktop.
Like NumberPicker, but with values min, max, initial in xml!
import android.content.Context;
import android.util.AttributeSet;
import android.widget.NumberPicker;
/**
* Created by Marlon on 26.03.2015.
*/
public class MyNumberPicker extends NumberPicker {
public MyNumberPicker(Context context) {
super(context);
}
public MyNumberPicker(Context context, AttributeSet attrs) {
super(context, attrs);
processAttributes(attrs);
}
private void processAttributes(AttributeSet attrs) {
this.setMinValue(attrs.getAttributeIntValue(null, "min", 0));
this.setMaxValue(attrs.getAttributeIntValue(null, "max", 100));
this.setValue(attrs.getAttributeIntValue(null, "initial", (this.getMaxValue() - this.getMinValue()) / 2)));
}
public MyNumberPicker(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
processAttributes(attrs);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment