注册界面,判断注册信息EditText框是否为空,空则使提交Button不能触发
private EditText ev1, ev2, ev3;
private Button btn1;
ev1 = (EditText) findViewById(R.id.et1);
ev2 = (EditText) findViewById(R.id.et2);
ev3 = (EditText) findViewById(R.id.et3);
btn1 = (Button) findViewById(R.id.login);
new Thread(){
<span style="white-space:pre"></span>public void run() {
<span style="white-space:pre"></span>if (ev1.getText().toString().equals("")
<span style="white-space:pre"></span>|| ev2.getText().toString().equals("")
<span style="white-space:pre"></span>|| ev3.getText().toString().equals(""))
<span style="white-space:pre"></span>btn1.setEnabled(false);
<span style="white-space:pre"></span>else
<span style="white-space:pre"></span>btn1.setEnabled(true);
<span style="white-space:pre"></span>};
}.start();
解决办法,使用定时器启动,每1s检测一次信息框是否填好
private Handler handler2 = new Handler();
handler2.postDelayed(runnable3,1000);
Runnable runnable3 = new Runnable() {
@Override
public void run() {
try{
if (ev1.getText().toString().equals("")
|| ev2.getText().toString().equals("")
|| ev3.getText().toString().equals(""))
btn1.setEnabled(false);
else
btn1.setEnabled(true);
handler2.postDelayed(this, 1000);
}catch(Exception e){
e.printStackTrace();
}
}
};