public class Admin extends Activity implements OnClickListener{
EditText password;
Button enter;
private int one=1;
private int zero=0;
private String pass;
protected static String PASSWORD="1234";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.password);
password=(EditText) findViewById(R.id.editText_password);
enter=(Button) findViewById(R.id.Button_enter);
enter.setOnClickListener(this);
}
@Override
public void onBackPressed() {
setResult(zero);
super.onBackPressed();
}
@Override
public void onClick(View v) {
pass=password.getText().toString();
if(pass.matches(PASSWORD)){
setResult(one);
Admin.this.finish();
}
else
password.setText("");
}
}
当我删除if条件然后它工作,但如果条件它给我错误:“应用程序密码管理器已被意外停止”。所以任何人可以帮助我,我提前感谢他。
答案 0 :(得分:3)
尝试更改:
if(pass.matches(PASSWORD)){
...
}
成:
if(pass.equals(PASSWORD)){
...
}