EditText setError 的使用
?/** called when the activity is first created. */<br>?edittext login_accountedt,login_passwordedt;<br>?button login_loginbtn;<br>??? @override<br>??? public void oncreate(bundle savedinstancestate) {<br>??????? super.oncreate(savedinstancestate);<br>??????? setcontentview(r.layout.main);<br>??????? login_accountedt=(edittext)findviewbyid(r.id.login_accountedt);<br>??????? login_passwordedt=(edittext)findviewbyid(r.id.login_passwordedt);<br>??????? login_loginbtn=(button)findviewbyid(r.id.login_loginbtn);<br>??????? login_loginbtn.setonclicklistener(new onclicklistener() {<br>???<br>??????? ?<br>???@override<br>???public void onclick(view v) {<br>????// todo auto-generated method stub<br>????system.out.println(login_accountedt.gettext().tostring() +"??? "+ login_passwordedt.gettext().tostring());<br>????if(isempty(login_accountedt) )<br>????{<br>?????login_accountedt.seterror("用户名不能为空!");<br>????}else<br>????{<br>?????login_accountedt.seterror(null);<br>????}<br>????if(isempty(login_passwordedt) )<br>????{<br>?????login_passwordedt.seterror("密码不能为空!");<br>????}else<br>????{<br>?????login_passwordedt.seterror(null);<br>????}<br>???}<br>??});<br>??????? <br>??? }<br>??? public boolean isempty(edittext... edittextes)<br>?{<br>??for (edittext et : edittextes)<br>??{<br>???if (et.gettext() == null)<br>????return true;<br>???if (et.gettext().tostring().trim().equals(""))<br>????return true;<br>??}<br>??return false;<br>?}<br>??? <br>??? <br>}