you use equals() method for string comparison. Because java supports this 
method for strings...

Try this:

EditText editText1 = (EditText) findViewById(R.id.editText1);
        String userName = editText1.getText().toString().trim();
       
        EditText editText2 = (EditText) findViewById(R.id.editText2);
        String password = editText2.getText().toString().trim();
        if(userName.equals(userName1) || password.equals(password1)){
             startActivity(intent);
        }
        else{
            Context context = getApplicationContext();
            CharSequence text = "Incorrect Username or Password!";
            int duration = Toast.LENGTH_SHORT;

            Toast toast = Toast.makeText(context, text, duration);
            toast.show();
        }

Regards
Android developer
Trinay Technology Solutions
www.trinaytech.com
5705750475

On Monday, February 4, 2013 1:50:02 AM UTC+5:30, [email protected] 
wrote:
>
> I am trying to create a login screen for your basic hello world program. I 
> do not need a database for this so I hard coded the username and password 
> directly into the code. The problem I am having is when I enter the correct 
> username and password, I get my error message stating that either one is 
> wrong. Here is the code I have, any help would be greatly appreciated. 
>
>     public void welcomeScreen(View view){
>         String userName1 = "student";
>         String password1 = "school";
>         Intent intent = new Intent(this, WelcomeScreen.class);
>         EditText editText1 = (EditText) findViewById(R.id.editText1);
>         String userName = editText1.getText().toString();
>         
>         EditText editText2 = (EditText) findViewById(R.id.editText2);
>         String password = editText2.getText().toString();
>         
>         if(userName != userName1 || password != password1){
>             Context context = getApplicationContext();
>             CharSequence text = "Incorrect Username or Password!";
>             int duration = Toast.LENGTH_SHORT;
>
>             Toast toast = Toast.makeText(context, text, duration);
>             toast.show();
>         }
>         
>         else startActivity(intent);
>     }
>

-- 
-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Android Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to