android - How to disable Button if EditText is empty ? -


i have edittext , button in application.

when button clicked,the text entered in edittext added listview.

i want disable button if edittext empty.how ?

this code button click

imagebutton imb=(imagebutton)findviewbyid(r.id.btn_send);             imb.setonclicklistener(new onclicklistener()             {              @override              public void onclick(view arg0)               {                   edittext et = (edittext)findviewbyid(r.id.edittext1);                    string str = et.gettext().tostring();                   web1.add(str);                   toast.maketext(shoutsingleprogram.this, "you entered...."+str, toast.length_short).show();                   adapter1.notifydatasetchanged();                   et.settext("");                      }             });             } 

how can ?

    edittext1.addtextchangedlistener(new textwatcher() {          @override         public void ontextchanged(charsequence s, int start, int before, int count) {                            if(s.tostring().trim().length()==0){                             button.setenabled(false);                            } else {                                 button.setenabled(true);                             }           }          @override         public void beforetextchanged(charsequence s, int start, int count,                 int after) {             // todo auto-generated method stub          }          @override         public void aftertextchanged(editable s) {             // todo auto-generated method stub          }     }); 

Comments

Popular posts from this blog

java - WrongTypeOfReturnValue exception thrown when unit testing using mockito -

php - Magento - Deleted Base url key -