Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid user log in
    text
    copied!<p>I am creating an application that lets the user log in to a profile they create, I just want to know how I would get a correct username and password entry to take the user to another activity as at the moment I just get errors if I try to use intent and startactivity.</p> <pre><code>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") &amp;&amp; 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); } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload