I want to disable by Button if the words in the EditText is less than 3 words, and if the words in the EditText are more than 3 words then I want to enable it so that it can get Clicked.
Can anyone help me here?
I want to disable by Button if the words in the EditText is less than 3 words, and if the words in the EditText are more than 3 words then I want to enable it so that it can get Clicked.
Can anyone help me here?
You have to
addTextChangedListener
to yourEditText
Like this:
In that method, you should do like this:
Hope it helps.
Most Easy Solution
This is very easy in Data-Binding. You can directly handle button state in XML depending on EditText.
Here
&
is HTML entity which denotes to&
.Here
etName
&etPassword
are corresponding ids for name & password EditText.Sample XML -
You can do what @Udaykiran says but use
arg0.length()
instead.The
Editable
also contains the length of the content of theTextEditor
that was changedThe problem with using afterTextChanged alone is at application start it can't disable the button initially until you start typing to your EditText.
This is how I implemented mine and it works great. Call this method inside your Activity's onCreate method