问题描述
我有2 EditTexts;一旦活动开始01和02我的按钮将被禁用,当这两个EditText上包含文字,按钮必须再次启用。但是我的按钮总是被禁用,并使用无法启用它 button.setEnabled(真);
谁能帮助我?
summit.setEnabled(假);
buttonEnable();
公共无效buttonEnable(){
如果(feedback.length()大于0&安培;&安培; email.length()大于0){
summit.setEnabled(真正的);
}其他{
summit.setEnabled(假);
}
}
你是正确的有关需要一个TextWatcher。该 afterTextChanged(编辑)
方法是一个你感兴趣的是这样的。打电话给你的 buttonEnable()
的方法从它和TextWatcher添加到任何适用的文本字段。 (貌似反馈和电子邮件
从您的样品。)
I have 2 EditTexts; 01 and 02. My button will be disabled once the activity is started and when these two EditText contain text, the button has to be enabled again. However my button is always disabled and can't enable it using button.setEnabled(true);
.
Can anyone help me with this?
summit.setEnabled(false);
buttonEnable();
public void buttonEnable(){
if (feedback.length()>0 && email.length()>0){
summit.setEnabled(true);
}else{
summit.setEnabled(false);
}
}
You're correct about needing a TextWatcher. The afterTextChanged(Editable)
method is the one you're interested in for something like this. Call your buttonEnable()
method from it, and add the TextWatcher to any applicable text fields. (Looks like feedback
and email
from your sample.)
这篇关于Android的:如何使我的按钮回来,如果EditText上是不是空的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!