public void myClick1(View v){
EditText txtUser = (EditText) findViewById(R.id.strUser);
EditText txtPwd = (EditText)findViewById(R.id.strPwd);
if (txtUser.equals("admin")){
Toast.makeText(getApplicationContext(),"Authentication Pass", Toast.LENGTH_LONG).show();
}else{
Toast.makeText(getApplicationContext(),"Not valid User ID/Password: " + txtUser.getText(), Toast.LENGTH_LONG).show();
}无论我在文本框中输入了什么,它都会激活else语句。为什么?
发布于 2015-06-12 15:34:07
您必须获得TextView的文本,如下所示:
EditText txtUser = (EditText) findViewById(R.id.strUser);
EditText txtPwd = (EditText) findViewById(R.id.strPwd);
if ("admin".equals(txtUser.getText().toString())) {
Toast.makeText(getApplicationContext(), "Authentication Pass", Toast.LENGTH_LONG).show();
} else {
Toast.makeText(getApplicationContext(),"Not valid User ID/Password: " + txtUser.getText(), Toast.LENGTH_LONG).show();
}发布于 2015-06-12 15:35:16
在进行如下比较时,应该使用txtUser.getEditableText().toString():
if ("admin".equals(txtUser.getEditableText().toString())){
Toast.makeText(getApplicationContext(),"Authentication Pass", Toast.LENGTH_LONG).show();
}else{
Toast.makeText(getApplicationContext(),"Not valid User ID/Password: " + txtUser.getText(), Toast.LENGTH_LONG).show();发布于 2015-06-12 15:37:24
我不熟悉android的自动取款机,但你试过:
txtUser.getText() == "admin“
谢谢您的评论(我使用的是C#方法),固定代码:
txtUser.getText().equals("admin")https://stackoverflow.com/questions/30806874
复制相似问题