如何一起处理两个 EditText 上的 addTextChangedListener?
How to handle addTextChangedListener on two EditText together?
要求:
有两个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;
}
要求。我正在尝试禁用软键盘后退按钮
以上代码无效!
创建一个函数来启用注册按钮
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();
}
要求:
有两个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;
}
要求。我正在尝试禁用软键盘后退按钮 以上代码无效!
创建一个函数来启用注册按钮
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();
}