我想我不明白爲什麼這不起作用logcat不告訴我任何事情,當我把onclick方法只是startactivity的意圖,它工作得很好。當我添加if語句時,它不會轉到其他activity.I檢查我是否正確輸入它。這是代碼。密碼和用戶名不起作用?
public class LoginActivity extends Activity {
String user;
String password;
String admin ="admin";
String pass ="lpt";
EditText username;
EditText passcode;
Button login;
Intent main = new Intent("android.intent.action.CONTROLS");
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
username = (EditText) findViewById(R.id.user);
passcode = (EditText) findViewById(R.id.passcode);
login = (Button) findViewById(R.id.Login);
login.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
user = username.getText().toString();
password = passcode.getText().toString();
if(user==admin && password == pass){
startActivity(new Intent("android.intent.action.CONTROLS"));
}
}
});
}
}
我覺得==是,如果這兩個都在同一個對象String.equals指向()時,你應該用什麼,我認爲 – JRowan