Android的:如何使我的按钮回来,如果EditText上是不是空的?使我、按钮、Android、EditText

2023-09-07 09:09:28 作者:浅唱、墨色年华

我有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);.

Android EditText和Button控件搭配如何更好看些

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.)