Nitin
Nitin

Reputation: 27

How to make edit text error position in android?

I have an app in which I have edit text fields in which I have to enter a mobile number and password. The problem is that the EditText error indicator covers the mobile number and password filed, and the user will not be able to enter mobile number. How do I solve this?

Screenshot

Upvotes: 2

Views: 4683

Answers (2)

Harshad Pansuriya
Harshad Pansuriya

Reputation: 20920

Use this android.support.design.widget.TextInputLayout. which can show the error below to the Edittext.so You can easily write next thing like your number and password in the new Edittext.

Here is xml code :

<LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="match_parent"
        android:layout_marginTop="?attr/actionBarSize"
        android:orientation="vertical"
        android:paddingLeft="20dp"
        android:paddingRight="20dp"
        android:paddingTop="60dp">

        <android.support.design.widget.TextInputLayout
            android:id="@+id/input_layout_name"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <EditText
                android:id="@+id/input_name"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:singleLine="true"
                android:hint="@string/hint_name" />
        </android.support.design.widget.TextInputLayout>

        <android.support.design.widget.TextInputLayout
            android:id="@+id/input_layout_email"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <EditText
                android:id="@+id/input_email"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:inputType="textEmailAddress"
                android:hint="@string/hint_email" />
        </android.support.design.widget.TextInputLayout>

        <android.support.design.widget.TextInputLayout
            android:id="@+id/input_layout_password"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <EditText
                android:id="@+id/input_password"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:inputType="textPassword"
                android:hint="@string/hint_password" />
        </android.support.design.widget.TextInputLayout>
</LinearLayout>

Let's see the ScreenShot for understand.

Empty Edittext.

enter image description here

Error message Edittext.

enter image description here

Upvotes: 11

user492888
user492888

Reputation: 207

@Nitin: Actually Edittext behaviour wants you to focus in the edittext to discard the seterror message to rectify the erroneous data and go to other fields.

Upvotes: 0

Related Questions