16 May 2015
Custom Preference for Android
I need a setting with a numeric value in my Android app. There is no obvious fit among the standard Preferences in Android, so I decided to implement my own Preference subclass.
This was a bit more involved than what I hoped for. I ended up with this. An improvement would be to be able to configure min and max values through XML attributes.
public class NumericPreference extends DialogPreference { private static final int DEFAULT_VALUE = 0; private NumberPicker mWidget; private int value = DEFAULT_VALUE; public NumericPreference(Context context, AttributeSet attrs) { super(context, attrs); setDialogLayoutResource(R.