3

I have tried multiple suggestions and nothing works :( I am trying to make the number keypad show up when this alert dialog box is show. Is there just some command to make the keyboard show up anyway?

void GetQuantity()

 {
  AlertDialog.Builder alert = new AlertDialog.Builder(this);
  alert.setTitle("Quantity");
  alert.setMessage("Enter Quantity");

  final EditText input = new EditText(this);

  alert.setView(input);
  input.setText("1");

  input.setInputType(DEFAULT_KEYS_DIALER |TYPE_NUMBER_FLAG_DECIMAL );

  input.setFilters(new InputFilter[] {
    // Maximum 5 characters.
    new InputFilter.LengthFilter(5),
  });

  alert.setPositiveButton("OK", new DialogInterface.OnClickListener() {

   @Override
   public void onClick(DialogInterface dialog, int which) {
    Quantity =Double.parseDouble( input.getText().toString());
    btnQuan.setText(input.getText().toString());

   }
  });


  alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
   public void onClick(DialogInterface dialog, int whichButton) {
    // do nothing
   }
  });
  alert.show();

 }
Mark Worsnop
  • 4,407
  • 15
  • 54
  • 79
  • what have you tried? i searched and found a few things but nothing 'simple'. this was the best i could find http://stackoverflow.com/questions/1509719/android-how-to-make-the-keypad-always-visible. – techi.services Jan 14 '11 at 21:06

3 Answers3

4

Someone else answered my question with this, and it works, but then their messsage went away?! Anyway here is the answer:

input.setInputType(InputType.TYPE_CLASS_NUMBER);
Mark Worsnop
  • 4,407
  • 15
  • 54
  • 79
  • 3
    It was me, but I thought after reading again your OP, that you wanted the keypad to pop up automatically at the same time the dialog appears. In the current situation, you need to tap on the edittext to make the keypad appear (and it is the numeric keypad) – ccheneson Jan 14 '11 at 21:17
2

Here is the complete answer:

This code is what you need. Just insert it wherever you need to launch the alert dialog. I haven't figured out how to launch the keyboard automatically , but it shouldn't be difficult.

AlertDialog.Builder alert = new AlertDialog.Builder(this);
                alert.setTitle(multiLangTranslation(R.string.manualshippermessage));
                final EditText input = new EditText(this);
                input.setInputType(InputType.TYPE_CLASS_NUMBER);
                input.setRawInputType(Configuration.KEYBOARD_12KEY);
                alert.setView(input);  
                alert.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int whichButton) {
                  //Put actions for OK button here
                  }
                });
                alert.setNegativeButton(multiLangTranslation(R.string.cancel), new DialogInterface.OnClickListener() {
                  public void onClick(DialogInterface dialog, int whichButton) {
                      //Put actions for CANCEL button here, or leave in blank
                  }
                });
                alert.show();
Josh
  • 6,251
  • 2
  • 46
  • 73
0

As suggested above use the command:

input.setInputType(InputType.TYPE_CLASS_NUMBER);

where to put this command in my code? I am looking to get a pop up when I press get input sort of button.

Pythonoid
  • 65
  • 10