0

I need to display an error message in edittext view when filed is empty or invalid.

Issue is when any edittext has error message prompt at that time if user open navigation drawer error message appear over the drawer.

I want navigation drawer always open over the error message. So when drawer close, user always have error message for invalid editext.

Note: This issue is not observed in Samsung device(Android 7.0) Observed in Moto and lenovo devices.

enter image description here

Images with error message over drawer.

enter image description here

<?xml version="1.0" encoding="utf-8"?>
<ScrollView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:paddingBottom="@dimen/padding_eextra_wide"
        android:paddingLeft="@dimen/activity_horizontal_margin"
        android:paddingRight="@dimen/activity_horizontal_margin"
        android:paddingTop="@dimen/padding_eextra_wide">

        <TextView
            android:id="@+id/tv_title"
            style="@style/Text.Medium"
            android:layout_gravity="center_horizontal"
            android:gravity="center_horizontal"
            android:inputType="textMultiLine"
            android:text="@string/title_add_care_recipient"
            android:textSize="@dimen/font_16pt"/>

        <TextView
            android:id="@+id/tv_sub_title"
            style="@style/Text.Medium"
            android:layout_gravity="center_horizontal"
            android:layout_marginLeft="@dimen/padding_20dp"
            android:layout_marginRight="@dimen/padding_20dp"
            android:gravity="center_horizontal"
            android:inputType="textMultiLine"
            android:lineSpacingMultiplier="1.2"
            android:text="@string/sub_title_add_care_recipient"
            android:textSize="@dimen/font_14pt"/>

        <android.support.design.widget.TextInputLayout
            style="@style/MaterialDesignTextInputLayout"
            android:layout_marginTop="@dimen/padding">

            <EditText
                android:id="@+id/et_first_name"
                style="@style/EditText.Medium.Mandatory"
                android:hint="@string/hint_first_name"
                android:maxLength="50"/>
        </android.support.design.widget.TextInputLayout>

        <android.support.design.widget.TextInputLayout
            style="@style/MaterialDesignTextInputLayout">

            <EditText
                android:id="@+id/et_last_name"
                style="@style/EditText.Medium.Mandatory"
                android:hint="@string/hint_last_name"
                android:maxLength="50"/>
        </android.support.design.widget.TextInputLayout>

            <Button
                android:id="@+id/btn_next"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:layout_marginLeft="@dimen/padding"
                android:background="@color/orange"
                android:textAllCaps="true"
                android:text="@string/text_save"/>

    </LinearLayout>

</ScrollView>
pratik03
  • 651
  • 2
  • 7
  • 23

1 Answers1

4

When your drawer open clear Focus form EditText using

editText.clearFocus();

OR

You have TextInputLayout so try to set Error on TextInputLayout .

And it's better to set error on TextInputLayout

textInputLayout.setError("Error message");
textInputLayout.setError(null);//for remove error
textInputLayout.setErrorEnable(false); //for remove error
ND1010_
  • 3,743
  • 24
  • 41
  • This can be last option to handled this issue. But I have 4 tabs at bottom and all contains 3-4 edittext fields. – pratik03 Dec 13 '17 at 10:58
  • 1
    yaa but i have seen your code xml you will use android.support.design.widget.TextInputLayout so its batter to use TextInputLayout.setError() method – ND1010_ Dec 13 '17 at 11:00