I want to launch different activities depending on the values of 2 EditText fields on the start activity, one should start for admins, the other for all other users.
I think you 'll understand better seeing the code I 've done so far:
package com.example.xxx;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.Button;
import android.widget.EditText;
import android.view.View;
public class MainScreenActivity extends Activity {
EditText USERNAME, PASSWORD;
String username, password;
Button btnLogin;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
USERNAME = (EditText) findViewById(R.id.username);
PASSWORD = (EditText) findViewById(R.id.password);
// Button
btnLogin = (Button) findViewById(R.id.btnLogin);
// login click event
btnLogin.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
// Launching next activity
if (USERNAME="admin" && PASSWORD="1234") {
Intent i = new Intent(getApplicationContext(), admin.class);
startActivity(i);
} else {
Intent i = new Intent(getApplicationContext(), user_form.class);
startActivity(i);
}
}
});
}
}
The error is at the if
statement, on PASSWORD="1234"
says "Incompatible operand types EditText and String". I also tried password="1234"
and password.toString="1234"
but no luck.
I'm not even sure if I'm to use 'USERNAME' and 'PASSWORD' or 'username' and 'password'. How can I make this work?
EDIT: Ok now the code is correct, having if (USERNAME.getText().equals("admin") && PASSWORD.getText().equals("1234"))
, but the application always opens the user_form
activity, and not the admin
, even though I input the specific values. Where is the mistake?