Beispiel #1
0
    @Override
    public void onCreatePromptView(
        LayoutInflater inflater, final ViewGroup container, Bundle savedInstanceState) {
      ViewGroup view = (ViewGroup) inflater.inflate(R.layout.prompt_number, container, true);

      numberPicker = (NumberPicker) view.findViewById(R.id.number_picker);
      numberPicker.requestFocus();
      numberPicker.setRange(getPrompt().min, getPrompt().max);
      numberPicker.setWholeNumbers(getPrompt().wholeNumbersOnly);
      numberPicker.setCurrent(getPrompt().defaultResponse);
      numberPicker.setOnChangeListener(
          new OnChangedListener() {
            @Override
            public void onChanged(NumberPicker picker, BigDecimal oldVal, BigDecimal newVal) {
              setValue(newVal);
            }
          });
      numberPicker.setImeActionLabel(getString(android.R.string.ok), R.id.submit_prompt);
      numberPicker.setOnEditorActionListener(
          new TextView.OnEditorActionListener() {
            @Override
            public boolean onEditorAction(TextView textView, int id, KeyEvent keyEvent) {
              if (id == R.id.submit_prompt || id == EditorInfo.IME_NULL) {
                if (getPrompt().hasValidResponse()) {
                  dispatchOkPressed();
                  return true;
                } else if (getPrompt().isSkippable()) {
                  dispatchSkipPressed();
                  return true;
                }
              }
              return false;
            }
          });
    }
Beispiel #2
0
 @Override
 protected void onSkipPressed() {
   super.onSkipPressed();
   numberPicker.setCurrent(null);
 }