2010-07-11 34 views
1

我很難搞清楚如何getText()作爲一個可讀的字符串從充氣EditText充氣EditText的內容

我有檢查一番一個布爾值的方法,因此,在onCreate方法我這樣稱呼它

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); 
      } 
} 

然後多數民衆贊成在我嘗試檢索的文本部分:

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 
      } 
    } 
} 

結果:

07-11 15:39:53.098: VERBOSE/Project(1239): mPassword: <b>[email protected]</b> password: 329349 

回答

3

進出口仍相當新的,我不知道太多關於EditTexts但通常在因爲它們是對象,所以我們不使用==來表示字符串。

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

會更正確。

+0

好吧我會試試! – 2010-07-11 16:47:00

+0

嘿男人!有效。我很欣賞男人,謝謝你的回答! – 2010-07-11 16:51:03

+0

很高興幫助:-) – Rasmus 2010-07-11 18:12:40