I want to to have some validation for my EditText wherein I want to show "" icon (that comes when you put editText.setError("blah blah"))
but don't want the text in the popup displaying that "blah blah".
Is there any way to do it? One way is to create a custom layout which will show the image icon in the EditText. But is there any better solution?
I have been dealing with the same problem. I wanted to use
.setError()
to myEditText
when user insert null input. But I think the pop-out message is annoying, especially when you have moreEditText
s. My solution was naive and simple, but it worked on all devices I've tried so far.I created my own class myEditText and just
@Override
this method:then use in
layout.xml
and finally in my code I put
onFocusChangeListener
tomyEditText
, so when someone clicks-in, the icon disappears.It works Exactly how I want = no pop-up message when
.setError()
is called onEditText
.This is the very useful when you want to show the error messages for the edittext field when the user enter wrong information.this is very simply program only you have to use serError() method in the edittext.
Step 1: Create button and implement onclickListener.
Step 2: Validate the input fields and set the error in the input field.
Refer this link for more:http://velmuruganandroidcoding.blogspot.in/2014/08/set-error-message-in-edittext-android.html
Sorry Rajkiran, but your solution is not working on Android 4.2 version. If I am trying to set
null
value for error, it is not even displayed. The solution I came up was to extendEditText
and overridesetError
method. No I have only error indicator without popup.You dont need to create a new
EditText
class or change xml. The solution is very simple:To get only the error-icon without an error-message-popup only when
setError("")
is called (i.e. set an empty String as error-message) I use a custom EditText-class where I overridesetError(CharSequence, Drawable)
like this:Everything else stays the same:
Use
setError(null)
to get neither the icon nor the message-popup.Use
setError(errorMessage)
, whereerrorMessage
is a String with length 1 at least, to get the icon and message-popup.Problem solved after a lot of research and permutations- (Also thanks to @van)
Create a new class that will extend
EditText
something like this-Use this class as a view in your xml like this-
Now in the third step, just set a
TextWatcher
to your custom text view like this-where
R.drawable.ic_error
=Keeping text null solves the problem But if we keep only null in setError(null), this won't show the validation error; it should be null along with second param.