views:

34

answers:

1

I've modified my previous code for login.

package log1.log2;


import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;



public class Login extends Activity implements OnClickListener{


    UserDB db = new UserDB(this);
/** Called when the activity is first created. */

    private EditText etUsername;
    private EditText etPassword;
    private Button btnLogin;//private Button btnRegister;
    private TextView lblResult;

    @Override

    public void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);

        setContentView(R.layout.main);
     // Get the EditText and Button References
        etUsername = (EditText)findViewById(R.id.usernametxt);
        etPassword = (EditText)findViewById(R.id.passwordtxt);
        btnLogin = (Button)findViewById(R.id.btnLogin);
        //btnRegister = (Button)findViewById(R.id.btnRegister);
        lblResult = (TextView)findViewById(R.id.msglbl);

        //Cursor c = (Cursor) db.getAllTitles();

        Button btnArrival = (Button) findViewById(R.id.btnRegister);
        btnArrival.setOnClickListener(this);


    // Set Click Listener
    btnLogin.setOnClickListener(new OnClickListener() {
    @Override
    public void onClick(View v) {
        db.open();
        // Check Login
        String username = etUsername.getText().toString();
        String password = etPassword.getText().toString();

        if(username.equals("")){
            if(password.equals(""))
                onClick();
            else
            {
                lblResult.setText("Wrong password");
            }

        } else {
            lblResult.setText("Username does not exist. Please register.");
        }

        db.close();
    }
});



    }

    public void onClick(View v)
    {

        if (v.getId() == R.id.btnLogin) 
        {
            Intent intent = new Intent(this, Test.class);
            startActivity(intent);
        } 
        else
        {
            Intent intent = new Intent(this, Home.class);
            startActivity(intent);
        }


}

}

As you can see, I've left a blank on my if..else. I do not know how to apply an sql statement to check the user and password.

if(username.equals("sqlstatement")){
            if(password.equals("sqlstatement"))
                onClick();
            else
            {
                lblResult.setText("Wrong password");
            }



 } else {
        lblResult.setText("Username does not exist. Please register.");
    }

I've insert onClick(); to direct to the other method so that the user will be directed to another page by using the onClickListener method, intent. But I'm having trouble doing that and so I thought that my code is wrong or there should be another way to direct to the other page once the user entered the correct username and password.

Before that, what should I do so that there would be a database connection? Or have I created a connection by inserting db.Open()?

I need to know the codes needed to be inserted the if..else statement.

Another basic stuff I want to know is how to set the text on the password edittext box to dots instead of the actual text.

A: 

Hi

for redirection pleae check my post on this issue http://android-pro.blogspot.com/2010/06/android-intents-part-2-passing-data-and.html

and to set the password TextView please check this

http://android-pro.blogspot.com/2010/03/android-text-controls.html

thanks

Mina Samy