I have a username and password field and now i need to check and redirect him to the next page in Android.
    public void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);   
         setContentView(R.layout.main);
         final EditText loginText = (EditText) findViewById(R.id.widget44);
         final EditText loginPassword = (EditText) findViewById(R.id.widget47);
         final Button button = (Button) findViewById(R.id.widget48);
            button.setOnClickListener(new View.OnClickListener() {
                public void onClick(View view) {
                 Intent myIntent = null;
                 if(loginText.getText().equals("admin") && 
loginPassword.getText().equals("admin")) {
                  System.out.println("Entering");
                  myIntent = new Intent(view.getContext(), Page1.class);
                 } else {
                 }
                 startActivity(myIntent);
                }
            });
        }
Temp now i am checking by hardcoding the values, but this too does not work for me. Why? I usually check in Java like this, why does it not accept me the same way in Android
I think it's because EditText#getText() returns an Editable object. Try
if(loginText.getText().toString().equals("admin") && 
    loginPassword.getText().toString().equals("admin")) {
    ...
}
                        Don't you need to put toString() to your textelements?
Like this:
if(loginText.getText().toString().equals("admin") && 
loginPassword.getText().toString().equals("admin")) {
...
Edit: neutrino was faster (+1) :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With