views:

21

answers:

1

I'm having a hard time figuring out how to getText() as a readable String from a inflated EditText.

I have a boolean method that checks something, so, in the onCreate method i call it like this

if(method) {
    if(booleanVariable) {
         LayoutInflater factory = LayoutInflater.from(MyActivity.this);
         View child = factory.inflate(R.layout.password, null);
         mPassword = (EditText)child.findViewById(R.id.password);
           }
}

Then thats the part where i try to retrieve the text:

private View.OnClickListener btnLoginListener = new View.OnClickListener() {        
@Override
public void onClick(View v) {
     if(mPassword!=null) {
          if(mPassword.getText().toString()==password) {                    
// LOGIN OK
            } else {
// NOT OK
            }
     }
}

Result:

07-11 15:39:53.098: VERBOSE/Project(1239): mPassword: <b>android.widget.EditText@43d3ba98</b> password: 329349
+2  A: 

Im still quite new and I don't know too much about EditTexts but normally in Java we don't use == for Strings since they are objects.

mPassword.getText().toString().equals(password)

would be more correct.

Rasmus
Alright i'll try!
Philipz
Hey man! It worked. I appreciate man, thank you for your answer!
Philipz
Glad it helped :-)
Rasmus