我的活动是一个简单的登录活动,其中(仅用于测试)如果用户名 && 密码相等,它将返回 true,否则返回 false。
但它总是返回假。
即使我转换toString();
示例也不行:
String a=(txtUserName.getText().toString() == txtPassword.getText().toString()) ? "equal" : "Nequal";
完整代码:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
txtUserName = (EditText) this.findViewById(R.id.txtUname);
txtPassword = (EditText) this.findViewById(R.id.txtPwd);
btnLogin = (Button) this.findViewById(R.id.btnLogin);
btnLogin.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(LoginActivity.this,txtUserName.getText(),Toast.LENGTH_LONG).show();
Toast.makeText(LoginActivity.this,"Just for separate", Toast.LENGTH_LONG).show();
Toast.makeText(LoginActivity.this,txtPassword.getText(), Toast.LENGTH_LONG).show();
String a=(txtUserName.getText() == txtPassword.getText()) ? "equal" : "Nequal";
Toast.makeText(LoginActivity.this, a, Toast.LENGTH_LONG).show();
}
});
}