title: Android Login page, database connection and checking of username and password. Edit text set to dots?
body: <p>I've modified my previous code for login. </p>
  
  <pre><code>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);
          }               
       }       
  }
  </code></pre>
  
  <p>As you can see, I've left a blank on my if..else. I do not know how to apply an <code>sql</code> statement to check the user and password. </p>
  
  <pre><code>if(username.equals("sqlstatement")){
              if(password.equals("sqlstatement"))
                  onClick();
              else
              {
                  lblResult.setText("Wrong password");
              }    
   } else 
          lblResult.setText("Username does not exist. Please register.");
  </code></pre>
  
  <p>I've insert <code>onClick</code>(); to direct to the other method so that the user will be directed to another page by using the <code>onClickListener</code> 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.</p>
  
  <p>Before that, what should I do so that there would be a <code>database</code> connection? Or have I created a connection by inserting <code>db.Open()</code>? </p>
  
  <p>I need to know the codes needed to be inserted the if..else statement.</p>
  
  <p>Another basic stuff I want to know is how to set the text on the password <code>edittext</code> box to dots instead of the actual text.</p>