Java – Error pop-ups in EditText not showing?

Error pop-ups in EditText not showing?… here is a solution to the problem.

Error pop-ups in EditText not showing?

I have an EditTextField with a DatepickerListener on it. If I press the submit button, it should validate the fields, and if they are empty, it should show an error message. To display this error message, I use the EditText.setError() method, but the popup window doesn’t appear. I don’t know how to fix it.

I tested it on 2 devices. Once on OnePlus 5 on Android 7.1.1 and once on Samsung Galaxy 7.0.0 on Android 7. The behavior is the same on both devices.

Thanks in advance.

Here is my code (virtual version):

private void initRequestButton(View view) {
    Button button = view.findViewById(R.id.submitButton);
    EditText dateTextField = view.findViewById(R.id.someField);        

button.setOnClickListener(v -> {
        String dateText = dateTextField.getText().toString();
        if (dateText.isEmpty()) {
                dateTextField.setError("A date is required");
        } else {
            do Something
        }
    });
}

Layout

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
app:errorEnabled="true">

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_margin="10dip"
    android:layout_marginTop="10dip"
    android:orientation="horizontal">

<EditText
        android:id="@+id/someField"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginBottom="20dip"
        android:layout_marginTop="20dip"
        android:layout_weight="0.5"
        android:clickable="false"
        android:cursorVisible="false"
        android:focusable="false"
        android:focusableInTouchMode="false"
        android:inputType="none" />

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_margin="10dip"
    android:layout_marginTop="5dip"
    android:orientation="horizontal">

<Button
        android:id="@+id/submitButton"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:layout_weight="0.3"
        android:text="@string/someText" />
</LinearLayout>

Solution

Just delete

 android:focusable="false"
    android:focusableInTouchMode="false"

Properties from editing text.

Related Problems and Solutions