Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

onClick event is not triggered on TextInputEditText android

I have the following TextInputEditText

<com.google.android.material.textfield.TextInputLayout
            android:focusableInTouchMode="true"
            android:id="@+id/from_textinput"
            style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_margin="8dp"
            android:fontFamily="sans-serif"
            android:hint="@string/from"
            android:textColor="@color/colorDarkGrey"
            android:textColorHint="@color/colorDarkGrey"
            android:textSize="12sp"
            android:textStyle="normal"
            android:visibility="gone"
            app:boxCornerRadiusBottomEnd="5dp"
            app:boxCornerRadiusBottomStart="5dp"
            app:boxCornerRadiusTopEnd="5dp"
            app:boxCornerRadiusTopStart="5dp"
            app:boxStrokeColor="@color/colorPrimary"
            app:boxStrokeWidth="3dp"
            app:layout_constraintEnd_toStartOf="@+id/to_textinput"
            app:layout_constraintHorizontal_bias="0.5"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/doNotDisturbCheckBox">

            <com.google.android.material.textfield.TextInputEditText
                android:onClick="@{() -> viewModel.openFromTimePickerClicked()}"
                android:focusableInTouchMode="true"
                android:id="@+id/from_textedit"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:editable="false"
                android:text="@{viewModel.doNotDisturbFrom}"
                android:textSize="16sp" />

        </com.google.android.material.textfield.TextInputLayout>

the problem that onClick is not triggered on the first touch, it is only called when I press for the second time

the first click make it focus the first click fire onClick

can anyone tell me how to fire click from the first time

like image 370
Amira Elsayed Ismail Avatar asked Mar 05 '23 16:03

Amira Elsayed Ismail


1 Answers

from_textedit.setEnabled(true);
from_textedit.setTextIsSelectable(true);
from_textedit.setFocusable(false);
from_textedit.setFocusableInTouchMode(false);
from_textedit.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View view) {
        Log.d(TAG, "Edit Text is clicked");
    }
});
like image 186
Hakan Saglam Avatar answered Mar 24 '23 19:03

Hakan Saglam