要求:
有两个EditText
一个是用户名,另一个是密码。
我正在检查两个EditText
有多个字符而不是注册按钮应该启用。
任何人都可以建议我吗?
etUsername.addTextChangedListener(new TextWatcher() {
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
// TODO Auto-generated method stub
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
// TODO Auto-generated method stub
}
@Override
public void afterTextChanged(Editable s) {
int userName = s.length();
if(userName >=1){
btnSignup.setEnabled(true);
}
}
});
etPswd = (EditText) findViewById(R.id.etpswd);
etPswd.addTextChangedListener(new TextWatcher() {
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
// TODO Auto-generated method stub
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
// TODO Auto-generated method stub
}
@Override
public void afterTextChanged(Editable s) {
int pswd = s.length();
if(pswd >=1) {
btnsignup.setEnabled(true);
}
}
});
etUsername.setOnKeyListener(this);
etPswd.setOnKeyListener(this);
private void trydisableLoginButton()
{
if(etUsername.getText().toString().length() == 0 && etPswd.getText().toString().length() == 0)
{ btnLogin.setEnabled(false);
}
}
@Override public boolean onKey(View v, int keyCode, KeyEvent event)
{
if(keyCode == KeyEvent.KEYCODE_BACK)
{
trydisableLoginButton();
}
return false;
}
所需物品。我正在尝试禁用返回按下softKeyboard上的按钮 上面的代码不起作用!
答案 0 :(得分:0)
创建一个启用注册按钮的功能
public void tryEnableSignUpButton(){
if(etUsername.getText().toString().lenght>=1 && (etPswd .getText().toString().lenght>=1 )){
btnSignup.setEnabled(true);
}
}
现在每个
之后 @Override
public void afterTextChanged(Editable s) {
int userName = s.length();
if(userName >=1){
tryEnableSignUpButton();
}
}
<强> @EDIT 强>
@Override
public void onBackPressed() {
trydisableLoginButton();
super.onBackPressed();
}