How to show the numeric keypad

廉价感情. 提交于 2019-12-02 22:30:36
Anju

give android:inputType="number" inside your xml file

Edit: "Number" does not work, changed to "number" (lowercase N)

a) in xml

android:numeric="decimal"

b) in code

EditText editView = new EditText(this);
editView.setKeyListener(new DigitsKeyListener());
lordhong

In your xml, you have to do this:

android:inputType="Number"

In your code, do:

editText.requestFocus();

Then:

InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(editText, InputMethodManager.SHOW_IMPLICIT);

Took me many days to figure this out. I even tried editText.performClick(); Not working.

To pop up a numeric keyboard on start of the activity i used following steps:

Created edit text field in layout as:

 <EditText
        ...
        android:inputType="number"    
        ...  />

In function onCreate() show soft keyboard

InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.toggleSoftInput(InputMethodManager.SHOW_FORCED,0);

Most important is to give focus to edit text in onResume method.

    @Override
    public void onResume() {
        super.onResume();
        editText.setFocusableInTouchMode(true);
        editText.requestFocus();
    }
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!