T
T
Tsuzukeru2020-09-07 10:33:03
Android
Tsuzukeru, 2020-09-07 10:33:03

Why doesn't the keyboard load sometimes when I press an EditText?

There is a simple fragment with EditText in the center. When the EditText is clicked, the View gets focus and the cursor starts blinking, then the keyboard is loaded, but sometimes the keyboard doesn't load even if the EditText gets focus and the cursor starts blinking. This happens even with the default EditText added from the Design Palette.
For example, with this one.

<EditText
        android:id="@+id/editTextTextPersonName"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:ems="10"
        android:inputType="textPersonName"
        android:text="Name"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/inputTextField" />


Why is this happening?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
T
Tsudzukeru, 2020-09-07
@Tsuzukeru

What is the problem and did not understand, but found a working solution.
You need to manually call the keyboard in a separate thread whenever the focus on the EditText changes.

editText.setOnFocusChangeListener(new OnFocusChangeListener() {
    @Override
    public void onFocusChange(final View v, final boolean hasFocus) {
        if (hasFocus && editText.isEnabled() && editText.isFocusable()) {
            editText.post(new Runnable() {
                @Override
                public void run() {
                    final InputMethodManager imm = (InputMethodManager)context.getSystemService(Context.INPUT_METHOD_SERVICE);
                    imm.showSoftInput(editText,InputMethodManager.SHOW_IMPLICIT);
                }
            });
        }
    }
});

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question