Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid 4.+ NumberPicker - Forcing Number Keyboard Layout
    text
    copied!<p>Am posting this in hopes to help someone else; but, if there is an easier way to do the same, I hope someone can share their steps. If I use the method 'setDisplayedValues' to pass an array of values to display in the NumberPicker, the underlying method forces the use of a Text Keyboard Layout, instead of the Number Layout, which isn't what I want. I found a way to set the InputType for my NumberPicker. This is done in my extended class:</p> <p><strong>class public class NumberPickerDialogFragment extends DialogFragment</strong>:</p> <pre><code>@Override public Dialog onCreateDialog(Bundle savedInstanceState) { // We are getting the parameters passed in to figure out the range of the Number Picker NumPickerValues = getArguments().getStringArray("NumPickerRange"); AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); // Get the layout inflater LayoutInflater inflater = getActivity().getLayoutInflater(); View dlgNumPicker = inflater.inflate(R.layout.dialog_num_picker, null); NumberPicker np = (NumberPicker) dlgNumPicker.findViewById(R.id.npNumberPicker); // Always remember that NumberPicker methods need an index position, rather than the value in that array position np.setMinValue(0); np.setMaxValue(NumPickerValues.length-1); np.setDisplayedValues(NumPickerValues); np.setValue(getArguments().getInt("InitialValue")); np.setWrapSelectorWheel(false); np.setOnValueChangedListener(this); // Since the underlying code for the NumberPicker sets the keyboard layout for text, due to the use of 'setDisplayedValues', // we need to set it back to a number keyboard layout ((EditText)np.getChildAt(0)).setRawInputType(InputType.TYPE_CLASS_NUMBER); // Inflate and set the layout for the dialog // Pass null as the parent view because its going in the dialog layout return builder.setView(dlgNumPicker) .setTitle(getArguments().getInt("NumPickerTitle")) .setPositiveButton(getArguments().getInt("SaveButtonTitle"), new ButtonCLickListener()) .setNegativeButton(R.string.cancel, new ButtonCLickListener()) .create(); } </code></pre> <p>On the section of code above, the line that sets the InputType is <strong>((EditText)np.getChildAt(0)).setRawInputType(InputType.TYPE_CLASS_NUMBER);</strong></p> <p>I didn't find anything on the web that does this. It seems like a clean way of doing it; but, am not sure if there is any performance issues by doing it this way. If there is, let us know.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload