Disable Button when Edit Text Fields empty

后端 未结 7 546
栀梦
栀梦 2020-12-31 04:22

I have two text fields and a Button. I want to disable the Button unless both EditText-Fields are not empty. I tried many solutions here at stackoverflow, but they don\'t wo

7条回答
  •  渐次进展
    2020-12-31 04:58

    I know this is old, but keep in mind that by simply using .isEmpty() will allow you to only add a space and the button will enable itself.

    Use s1.trim().isEmpty || s2.trim().isEmpty() instead.

    Or, you can do:

    String s1 = editText1.getText().toString().trim() String s2 = editText2.getText().toString().trim()

    then just check for .isEmpty().

    I don't know, it's however you'd want to do it, and this answer is most likely irrelevant anyway but I'd thought I'd just point that out.

提交回复
热议问题