Code example for NumberPicker

Methods: setFormattersetMaxValuesetMinValuesetWrapSelectorWheel, setFocusable, setFocusableInTouchMode, setLayoutParams

0
     * @return NumberPicker The that represents the number picker 
     */ 
    private NumberPicker createNumberPicker(
            int maxValue, TextView toAlignWith, TextView toHeightOf, final String format) {
        // Create the NumberPicker 
        NumberPicker digit = new NumberPicker(getContext());
        LayoutParams params = new RelativeLayout.LayoutParams(
                android.view.ViewGroup.LayoutParams.WRAP_CONTENT,
                android.view.ViewGroup.LayoutParams.WRAP_CONTENT);
        params.addRule(RelativeLayout.ALIGN_LEFT, toAlignWith.getId());
        params.addRule(RelativeLayout.ALIGN_RIGHT, toAlignWith.getId());
        params.addRule(RelativeLayout.ALIGN_TOP, toHeightOf.getId());
        params.addRule(RelativeLayout.ALIGN_BOTTOM, toHeightOf.getId());
        digit.setLayoutParams(params);
        digit.setMinValue(0);
        digit.setMaxValue(maxValue);
        digit.setValue(0);
        digit.setWrapSelectorWheel(false);
        digit.setFocusable(false);
        digit.setFocusableInTouchMode(false);
        digit.setVisibility(View.INVISIBLE);
        if (format != null) {
            digit.setFormatter(new NumberPicker.Formatter() {
                public String format(int value) {
                    return String.format(format, Integer.valueOf(value));
                } 
            }); 
        }