Java 如果输入正确,如何使(EditText)自动将用户发送到其他页面?不需要按钮。安卓工作室
我正在做毕业设计,我需要你们的帮助! 我使用安卓工作室。。 我需要一种方法,使字段EditeText在输入正确密码后执行操作 操作是:将用户直接移动到另一个页面。 无需按下按钮。 我尝试了这个代码,但什么也没发生Java 如果输入正确,如何使(EditText)自动将用户发送到其他页面?不需要按钮。安卓工作室,java,android,android-studio,if-statement,android-edittext,Java,Android,Android Studio,If Statement,Android Edittext,我正在做毕业设计,我需要你们的帮助! 我使用安卓工作室。。 我需要一种方法,使字段EditeText在输入正确密码后执行操作 操作是:将用户直接移动到另一个页面。 无需按下按钮。 我尝试了这个代码,但什么也没发生 pass= findViewById(R.id.password); pass.addTextChangedListener(enter); } private TextWatcher enter = new TextWatcher() { @Overr
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 start, 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);
}
非常感谢,现在开始工作了!你帮了我很多。再次感谢你