IF-Else loop use in android to compare a string with EditText?

Go To StackoverFlow.com

0

This If Else does not work hence does not direct to the menu page. I want to compare string with EditText input so I changed it to string. How can I compare string inputs in both fields and compare them with my string IF-Else loop and start the intent

package mjour.fyp;

      public class Login extends Activity{

EditText username;
EditText password;
Button login;
String name, pass;
String lname = "mehdi";



public void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.userlogin);

     login = (Button) findViewById(R.id.blog);
     username = (EditText) findViewById(R.id.editText1);
     name = username.getText().toString();   
     password = (EditText) findViewById(R.id.editText2);
     pass = password.getText().toString();  

     login.setOnTouchListener(new OnTouchListener() {

        public boolean onTouch(View v, MotionEvent event) {
            // TODO Auto-generated method stub

            Intent myintent = new Intent("mjour.fyp.MENU");
            if(name.contentEquals(lname))
            startActivity(myintent);

            return false;

     };});}}
2012-04-05 20:24
by mmehdisalehi


0

Are you missing an else after the startActivity()?

2012-04-06 01:24
by Stuart Siegler
I added the else statement, the else statement works fine, but the if statement for comparison b/w string and edittext is not working. any idea - mmehdisalehi 2012-04-06 09:00
I think you should be using compareTo() rather than contentEquals( - Stuart Siegler 2012-04-06 10:45
Ads