私は自分が作成したプロフィールにユーザーがログインできるアプリケーションを作成していますが、正しいユーザー名とパスワードを取得して、その時点で別のアクティビティに移動させる方法を知りたいだけですインテントとスタートアビリティを使用しようとするとエラーになります。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
上記の私のコメントを更新しました。うまくいけば役立ちます。 – xil3