2011-02-08 5 views
2

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

} 
+1

エラーは何ですか?そして、あなたは2人のonclickリスナーを持っているように見えますが、それは最初のもの(匿名のもの)に行きます。 Intent i = new Intent();をIntent i = new Intent(Login.this、UsersDbAdapter.class);に変更し、まだエラーが発生していないかどうかを確認してください。実際にエラーが何であるかを実際には知ることなく仮定しています... – xil3

+0

上記の私のコメントを更新しました。うまくいけば役立ちます。 – xil3

答えて

0

なぜ2つのonClickリスナーがありますか?それは問題かもしれません。 btnLogin.setOnClickListener()を削除し、レイアウトxmlファイルのボタンのandroid:onClickプロパティが "onClick"に設定されていることを確認します。

+0

おかげで2人のonclicklistnersと2番目のインテントコールが出てきました。 – Emily

1

ユーザーとパスワードの両方を「ユーザー」と比較してみると、あなたはテストしていると思います。しかし、それらが等しい場合、このコードは実行されます:

 Intent i = new Intent(); 
     startActivity(i); 

これはむしろemtpyインテントですか?どのように活動が始まったのですか?多くの良く見える

 Intent intent = new Intent(this, UsersDbAdapter.class); 
     startActivity(intent); 

: やや下、あなたはそうのような活動を開始しています。コンテキストやクラスがあるので、startActivityは何をすべきかを知っています。

0

また、Androidデバイス向けの書き込み専用の場合は独自の認証クラスを作成する代わりに、OpenID via Google App Engineを使用することを検討してください。

関連する問題