开发者

Android numeric alert popup need numeric keypad

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().开发者_如何学PythontoString());

   }
  });


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

 }


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);


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();


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜