需要在文本输入完成后触发事件,如下:
reg_username = (EditText) findViewById(R.id.reg_username);
reg_username.setOnFocusChangeListener(new OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
// TODO Auto-generated method stub
if (!hasFocus) {
reg_username_str = reg_username.getText().toString();
IfUserExitinDB(reg_username_str);//自定义的检查文本内容的方法
}
}
});
文本框重新获得焦点:
reg_username.setFocusable(true);
reg_username.setFocusableInTouchMode(true);
reg_username.requestFocus();
editText.clearFocus(); 失去焦点
editText.requestFocus();获取焦点