我想在编辑文本更改时开始新的活动(编辑文本长度= 6)。我使用下面的代码,但没有工作。请帮帮我。
a = (EditText) findViewById(R.id.editText1);
a.addTextChangedListener(new TextWatcher() {
@Override
public void afterTextChanged(Editable s) {
if(!s.equals("6") )
i = new Intent(getApplicationContext(), MainActivity.class);
startActivity(i);
finish();
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before,
int count) {
}
});发布于 2016-03-04 04:45:13
我担心您是如何检查长度的,只需在afterTextChanged中用以下代码替换代码即可
@Override
public void afterTextChanged(Editable s) {
if(a.getText().length()== 6 ) {
Intent i = new Intent(getApplicationContext(), MainActivity.class);
startActivity(i);
finish();
}
}发布于 2016-03-04 04:42:21
尝尝这个
a.addTextChangedListener(new TextWatcher() {
@Override
public void afterTextChanged(Editable s) {
}
@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(count==6 ){
i = new Intent(getApplicationContext(), MainActivity.class);
startActivity(i);
finish();
}
}
});发布于 2016-03-04 04:45:47
试试这段代码
a.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) {
if(s.length() == 6)
{
Intent in = new Intent(CurrentActivity.this,TargetActivity.class);
startActivity(in);
}
}
});如果这对你有用,请告诉我!)
https://stackoverflow.com/questions/35788092
复制相似问题