Last active
August 29, 2015 14:17
-
-
Save Regenhardt/73fe9e679985ec3d7dda to your computer and use it in GitHub Desktop.
Like NumberPicker, but with values min, max, initial in xml!
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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