Home » Android » How can I remove edittext error and request focus in android?

How can I remove edittext error and request focus in android?

Posted by: admin June 15, 2020 Leave a comment

Questions:

When I set error and request focus on edittext then it sets an error and request focus but how can I remove error and remove focus ?

mEditTextSearchOrAdd.setError("Error");
mEditTextSearchOrAdd.requestFocus();
How to&Answers:

You should do the following :

mEditText.setError(null);//removes error
mEditText.clearFocus();

Answer:

Example
=======
xml
---
 <EditText
                        android:id="@+id/name"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        />


java
-----
private EditText EditText1;
username = (EditText) findViewById(R.id.name);
username .setError(null);