简体   繁体   中英

EditText, focus, soft keyboard troubles

OK I have an array of EditTexts, and I want to loop through them, so if some EditText does not contain text, I want to ask user for input, and I'm through a lot of hours and a lot of reading but I can not understand how this is supposed do work. So few questions:

Is requestfocus() enough ? (It's not working - keyboard does not show)

I have tried with OnFocusChangeListener and than tried to Show keyboard (showSoftInput(view,InputMethodManager.SHOW_IMPLICIT)) if there is focus on editText again it is not working.

Does anyone know of any good example to get me out of this triangle?

view.requestFocus() is not enough;

I'm using this code:

public static void setSoftwareKeyboardVisibility(Context context, View view, boolean value) {
        final InputMethodManager manager = (InputMethodManager) context.getSystemService(Service.INPUT_METHOD_SERVICE);
        if (value) {
            view.requestFocus();
            manager.showSoftInput(view, InputMethodManager.SHOW_IMPLICIT);
        } else {
            // Any other not EditText View
            manager.hideSoftInputFromWindow(view.getWindowToken(), InputMethodManager.RESULT_UNCHANGED_SHOWN);
            view.requestFocus();
        }
    }

But You said that standatr method is not working. Try to call showSoftInput not in OnFocusChange method. Call it when you setting focus on EditText.

我现在无法找到解决问题的页面,但是解决方法如下:

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

With editText.requestFocus() where editText is your EditText View you focus the cursor to the field.

If you want to show the keyboard after focusing, look at the answer of raukodraug here .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM