我正在創建一個應用程序,允許用戶登錄到他們創建的配置文件,我只想知道我將如何獲得正確的用戶名和密碼條目,以便將用戶帶到目前的其他活動如果我嘗試使用intent和startactivity,我只會遇到錯誤。Android用戶登錄
public class Login extends Activity implements OnClickListener{
/** Called when the activity is first created. */
private EditText etUsername;
private EditText etPassword;
private Button btnLogin;
//private Button btnRegister;
private TextView lblResult;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.login);
// Get the EditText and Button References
etUsername = (EditText)findViewById(R.id.EditUsername);
etPassword = (EditText)findViewById(R.id.EditPassword);
btnLogin = (Button)findViewById(R.id.login);
//btnRegister = (Button)findViewById(R.id.btnRegister);
lblResult = (TextView)findViewById(R.id.lblmsg);
// Button btnArrival = (Button) findViewById(R.id.btnRegister);
//btnArrival.setOnClickListener(this);
// Set Click Listener
btnLogin.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// Check Login
String username = etUsername.getText().toString();
String password = etPassword.getText().toString();
if(username.equals("User") && password.equals("user")){
Intent i = new Intent();
startActivity(i);
} else {
lblResult.setText("Login failed. Username and/or password doesn't match.");
}
}
});
}
public void onClick(View v)
{
Intent intent = new Intent(this, UsersDbAdapter.class);
startActivity(intent);
}
}
有什麼錯誤?它看起來像你有2個onclick監聽器,但它是第一個(匿名監聽器)。將Intent i = new Intent();`更改爲`Intent i = new Intent(Login.this,UsersDbAdapter.class);`並查看是否仍然出現錯誤。假設沒有真正知道錯誤是什麼... – xil3 2011-02-08 14:40:17
剛剛更新了我的評論上面 - 希望這有助於。 – xil3 2011-02-08 14:45:00