根据的EditText在Android上的文本启用和禁用按钮 [英] Enable and disable Button according to the text in EditText in Android
本文介绍了根据的EditText在Android上的文本启用和禁用按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想禁用通过按钮,如果在的EditText的话不到3个字,如果在EditText上的话3个以上的话那么我想启用它,使它能获得点击。
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.
谁能帮助我在这里?
推荐答案
您必须 addTextChangedListener
您EdiText
You have to addTextChangedListener
to your EdiText
这样的:
yourEditText.addTextChangedListener(new TextWatcher() {
@Override
public void afterTextChanged(Editable arg0) {
enableSubmitIfReady();
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
}
});
在该方法中,你应该做的是这样的:
In that method, you should do like this:
public void enableSubmitIfReady() {
boolean isReady =yourEditText.getText().toString().length()>3;
yourbutton.setEnabled(isReady);
}
希望它帮助。
Hope it helps.
这篇关于根据的EditText在Android上的文本启用和禁用按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文