0

I have an cardview adapter where each card is a form of filling in a mandatory value (if the user want to save the value) and an optional commentbox. This mandatory value and the optional commentbox are TextInputEditText-fields within TextInputLayouts. In the code behind I have Textwatchers for each field. The value-field looks through the input and validates the value. If it is valid, the commentbox will be enabled and the value will be set onto an object. The textwatcher for the commentbox only takes the string in the input and sets it onto the same object. ex. object.setValue(); object.setComment();

I have implemented it like this in the UI:

<TextView android:id="@+id/txt_value_title" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Value:*" android:textAppearance="@style/Bold.FontPath" android:textSize="@dimen/cardview_textsize_header" android:textStyle="bold" />

`<com.google.android.material.textfield.TextInputLayout
            android:id="@+id/layout_edt_value"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:endIconMode="clear_text">

    <com.google.android.material.textfield.TextInputEditText
                android:id="@+id/edt_value"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginRight="@dimen/twenty_dp"
                android:background="@drawable/rounded_border"
                android:inputType="text"
                android:lines="1"
                android:maxLines="1"
                android:textColor="@color/black"
                android:textSize="@dimen/cardview_textsize_header" />
</com.google.android.material.textfield.TextInputLayout>

<TextView
    android:id="@+id/txt_commentbox_title"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:layout_marginTop="@dimen/ten_dp"
    android:text="Title"
    android:textAppearance="@style/Bold.FontPath"
    android:textSize="@dimen/cardview_textsize_header"
    android:textStyle="bold" />

<com.google.android.material.textfield.TextInputLayout
    android:id="@+id/layout_edt_comment"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    app:counterEnabled="true"
    app:counterMaxLength="255"
    app:endIconMode="clear_text">

    <com.google.android.material.textfield.TextInputEditText
        android:id="@+id/edt_comment"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:lines="2"
        android:gravity="top"
        android:background="@drawable/rounded_border"
        android:inputType="textMultiLine|textCapSentences"
        android:maxEms="255"
        android:maxLength="255"
        android:maxLines="3"/>
</com.google.android.material.textfield.TextInputLayout>`

The issue is that the value-input works completely fine with an external keyboard. But when I focus on the commmentbox, after one key-press it selects my "back"-button in the header. It works completely fine on previous android version before Android 12.

I have been analysing events in the code behind, but there is nothing that would seem to alter the commentbox at all after an edit except for saving the string-value onto an object with a textwatcher.

I have however found that this pops up in the log only for the commentbox-edittext: W/IInputConnectionWrapper: getTextBeforeCursor on inactive InputConnection W/IInputConnectionWrapper: getTextAfterCursor on inactive InputConnection W/IInputConnectionWrapper: getSelectedText on inactive InputConnection This feels like it would be the issue but I can not find a solution to this.

Does anyone have any idea?

I have tried changing the UI. I have tried using EditTexts. I have tried updating "com.google.android.material:material:1.3.0" to the latest version. I have also looked through the logic of the whole code-behind and removed triggers completely to see if it would change anything. I have added an new clean editText which works, But my commentbox is still the one that is not working as intended.

1 Answer 1

0

After further testing in the UI I found a work-around. It is not exactly what I hoped for but it works. In my TextInputLayout, when counterEnabled is true, it automatically deselects the EditText on text changed.

> <com.google.android.material.textfield.TextInputLayout
>     android:id="@+id/layout_edt_comment"
>     android:layout_width="match_parent"
>     android:layout_height="wrap_content"
>     app:counterEnabled="true"
>     app:counterMaxLength="255"
>     app:endIconMode="clear_text"></com.google.android.material.textfield.TextInputLayout>

So I removed it and it works now. Does anyone know the true solution to this though? I do need a text counter. I could also add a textviewer and update it in the TextWatcher. But that still feels like a work-around.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.