Show an EditText error when the user is not focused on this editText

I have an editText that is currently showing a pop-up error message.

editText.setError ("You did something wrong");

Now I need a workflow, so when the user clicks the button elsewhere, I need to set the error in editText. But now only the error icon is displayed.

My question is: is it possible for it to display all the error text without actually clicking (focusing) on ​​it?

+4
source share
2 answers

Solution 1

Call

editText.requestFocus()

before setting the error.

Decision 2

Use TextInputLayout.

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

        <EditText
            android:layout_width="match_parent"
            android:layout_height="wrap_content"/>
    </android.support.design.widget.TextInputLayout>

And in code

textInputLayout.setError("Error");

Decision 3

Custom view, up to you.

+2

MaterialEditText, ... wiki.

:

app:met_helperText="Integer"

:

setError ( CharSequence) java-.

:

validationEditText.isValid("\\d+");

regex :

validationEditText.validate("\\d+", "Only Integer Valid!");
+1

Source: https://habr.com/ru/post/1662161/


All Articles