Adnan Pirota
Adnan Pirota

Reputation: 309

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?

Upvotes: 0

Views: 636

Answers (3)

malliaridis
malliaridis

Reputation: 494

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.

Upvotes: 0

Adnan Pirota
Adnan Pirota

Reputation: 309

I can not find now the page where I got resolution to my problem, but the solution was as follows:

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

Upvotes: 0

nfirex
nfirex

Reputation: 1523

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.

Upvotes: 1

Related Questions