我有编辑文本的问题。我想如果编辑文本是六个字符转到下一个actitvity。我写这段代码,但如果写六个字符不进行下一个活动。
这是我的代码
smsCode.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
if (s.toString().trim().length()== 6){
Intent intent = new Intent(SmsCodeActivity.this,ScanQrCodeActivity.class);
startActivity(intent);
}
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
}
@Override
public void afterTextChanged(Editable s) {
}
});
答案 0 :(得分:1)
smsCode.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
if(smsCode.getText().toString().trim().length()== 6){
Intent intent = new Intent(SmsCodeActivity.this,ScanQrCodeActivity.class);
startActivity(intent);
}
}
@Override
public void afterTextChanged(Editable s) {
}
});
答案 1 :(得分:0)
尝试在onTextChanged
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
if (smsCode.getText().toString().trim().length()== 6){
Intent intent = new Intent(SmsCodeActivity.this,ScanQrCodeActivity.class);
startActivity(intent);
}
}