如何解决如果输入正确,如何使EditText自动将用户发送到其他页面?无需按钮 Android Studio
我正在做一个毕业设计,我需要你的帮助! 我使用Android Studio .. 而且我需要一种方法,可以在输入正确的密码后使字段EditeText起作用
,操作是:将用户直接移动到另一个页面。 无需按下按钮。 我尝试使用此代码,但没有任何反应
pass= findViewById(R.id.password);
pass.addTextChangedListener(enter);
}
private TextWatcher enter = new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s,int start,int count,int after) {
}
@Override
public void onTextChanged(CharSequence s,int before,int count) {
//EditText.OnEditorActionListener
if(pass.getText().toString().trim()=="123123"){
Intent intent = new Intent(log_page.this,Casher.class);
startActivity(intent);
}
}
@Override
public void afterTextChanged(Editable s) {
String passAccount= pass.getText().toString().trim();
if(pass.getText().toString().trim()=="123123"){
Intent intent = new Intent(log_page.this,Casher.class);
startActivity(intent);
}
}
};
解决方法
在Java中检查彼此的字符串是否相等,您需要使用equals
方法而不是==
,因为==
将检查字符串的引用和对象:
if(pass.getText().toString().trim().equals("123123")){
Intent intent = new Intent(log_page.this,Casher.class);
startActivity(intent);
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。