EditText is not showing virtual keyboard

2019-09-08 20:50发布

I have created a dynamic screen with editText in it..but after click it is not showing the virtual keyboard.I have added these following codes..but still ot worked.

getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);

and this also dint worked

InputMethodManager im = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);

im.showSoftInput(edittext, 0);

my code is here...

runOnUiThread(new Runnable() {
            public void run() {
                LinearLayout findViewById = (LinearLayout) findViewById(R.id.dynamicInputs);
                //TextView textView = (TextView) findViewById(R.id.name);
                TextView textView = new TextView(Activity_UserInput.this);
                textView.setText("   " + map.get(KEY_NAME) + " :");
                textView.setTextColor(Color.BLACK);
                textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 17);
                //textView.setLayoutParams(new LayoutParams(Layout.DIR_LEFT_TO_RIGHT, Gravity.CENTER_VERTICAL));

                findViewById.addView(textView);

                EditText editText = new EditText(Activity_UserInput.this);
                editText.setText("");
                //editText.setInputType(InputType.TYPE_CLASS_NUMBER);  

                findViewById.addView(editText);

            }

3条回答
男人必须洒脱
2楼-- · 2019-09-08 21:15

try this

InputMethodManager mgr = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);

mgr.showSoftInput(editText, InputMethodManager.SHOW_IMPLICIT);
查看更多
3楼-- · 2019-09-08 21:34

Remove from XML

Android:isFocusable="false"

If it is not post your XML please

Btw this

 getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE)

Is correct

查看更多
虎瘦雄心在
4楼-- · 2019-09-08 21:35

Let me try, I think you need to set focus on editText like..

    editText.setFocusableInTouchMode(true);
    editText.requestFocus();

I am not sure but try it and let me know it works or not.

查看更多
登录 后发表回答