【问题标题】:Android numeric alert popup need numeric keypadAndroid 数字提示弹窗需要数字小键盘
【发布时间】:2015-02-23 20:32:44
【问题描述】:

我尝试了多个建议,但没有任何效果:(我试图在显示此警报对话框时显示数字键盘。是否只有一些命令可以让键盘显示?

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

 }

【问题讨论】:

标签: android alert


【解决方案1】:

其他人用这个回答了我的问题,它有效,但是他们的消息消失了?! 无论如何,这是答案:

input.setInputType(InputType.TYPE_CLASS_NUMBER);

【讨论】:

  • 是我,但我想在再次阅读您的 OP 后,您希望键盘在对话框出现的同时自动弹出。目前情况下,需要点击edittext让小键盘出现(而且是数字小键盘)
【解决方案2】:

这是完整的答案:

此代码正是您所需要的。只需将其插入您需要启动警报对话框的任何位置。 还没想好怎么自动启动键盘,不过应该不难。

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

【讨论】:

    【解决方案3】:

    按照上面的建议使用命令:

    input.setInputType(InputType.TYPE_CLASS_NUMBER);
    

    在我的代码中把这个命令放在哪里?当我按下获取输入类型的按钮时,我希望得到一个弹出窗口。

    【讨论】:

      猜你喜欢
      • 2012-10-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-11-24
      • 2011-06-08
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多