Android developers EditText press the Enter button to appear focus search returned a view that was not able to take focus! Error

Problem Description

  When EditText View this became item ListView or RecyclerView, and when you press the input method Enter / Next / next will appear in focus search returned a view that was not able to take focus! Being given. 

 

problem causes

  Because after you press the Enter key, the focus will automatically switch to the next EditText. This time if you hide or next EditText itself is not loaded. The error appeared. The error means that the focus of my goals is lost, can not find to the next EditText.

 

Solution

The first:

  Setting android EditText property in:. ImeOptions = "actionUnspecified" imeOptions specific role is to control the properties of the Enter key

<EditText
        android:id="@+id/title_content"
        android:layout_width="0dp"
        android:layout_height="60dp"
        android:hint="请输入标题"
        android:singleLine="true"
        android:maxLength="20"
        android:inputType="text"
        android:imeOptions="actionUnspecified"
        app:layout_constraintTop_toBottomOf="@id/cover_barrier"
        app:layout_constraintLeft_toRightOf="@id/title"
        app:layout_constraintRight_toRightOf="parent"/>

  If the property is set actionUnspecified will still be an error, you can try another property actionNone

The second:

  This approach is listening Editor operations, and then press Enter write operation function they need (the Enter key or other key substitution logic you want to achieve). ... or simply do not write in this way is relatively simple violence

            mEditView.setOnEditorActionListener(new TextView.OnEditorActionListener() {
                @Override
                public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
                    return true;
                }
            });

Attention to the need to return true if you have treated this incident.

 

Guess you like

Origin www.cnblogs.com/guanxinjing/p/11354390.html