2011-01-14 74 views
2

我已经尝试了多个建议,没有任何工作:(我试图让数字键盘显示当这个警报对话框显示。是否有一些命令,使键盘显示反正?Android数字警报弹出需要数字小键盘

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

} 
+0

你试过了什么?我搜索并发现了一些东西,但没有“简单”。这是最好的,我可以找到http://stackoverflow.com/questions/1509719/android-how-to-make-the-keypad-always-visible。 – techiServices 2011-01-14 21:06:28

回答

4

别人回答我这个问题,和它的作品,但随后他们的讯息话题走了?! 反正这里是答案:

input.setInputType(InputType.TYPE_CLASS_NUMBER); 
+3

这是我的,但我想再次阅读您的OP后,想让键盘在对话框出现的同时自动弹出。在目前的情况下,你需要点击edittext使键盘出现(并且它是数字键盘) – ccheneson 2011-01-14 21:17:02

1

下面是完整的答案:

这段代码就是你需要的。只需将其插入需要启动警报对话框的任何位置即可。 我还没有想出如何自动启动键盘,但它不应该是困难的。

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

正如上文建议使用命令:

input.setInputType(InputType.TYPE_CLASS_NUMBER); 

哪里在我的代码把这个命令?当我按下输入类型的按钮时,我正在查看弹出窗口。