我正在创建一个应用程序,允许用户登录到他们创建的配置文件,我只想知道我将如何获得正确的用户名和密码条目,以便将用户带到目前的其他活动如果我尝试使用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