1
我有一個活動,其中包括一些EditText的自我創建的登錄系統,我也包括一個Facebook登錄按鈕。當我從活動中註釋掉下面的FB代碼段時,我可以檢索EditTexts的值。但是,使用FB代碼,所有EditText值都會變回空。爲什麼是這樣?Android在同一活動中使用Facebook登錄和EditText?
public class LoginActivity extends FragmentActivity
{
private EditText mEmailRegisterView;
private EditText mPasswordRegisterView;
private EditText mPasswordConfirmRegisterView;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
// Set FB fragment
// Commenting this if/else allows the EditText values to be obtained.
if (savedInstanceState == null)
{
// Add the fragment on initial activity setup
loginFragment = new LoginFragment();
getSupportFragmentManager().beginTransaction()
.add(android.R.id.content, loginFragment).commit();
}
else
{
// Or set the fragment from restored state info
loginFragment = (LoginFragment) getSupportFragmentManager().findFragmentById(
android.R.id.content);
}
...
// Get the register EditText objects
mEmailRegisterView = (EditText) findViewById(R.id.login_activity_email_register);
mPasswordRegisterView = (EditText) findViewById(R.id.login_activity_password_register);
mPasswordConfirmRegisterView = (EditText) findViewById(R.id.login_activity_password_confirm_register);
Button registerButton = (Button) findViewById(R.id.register_button);
registerButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View view)
{
// Store values at the time of the login attempt.
mEmailRegister = mEmailRegisterView.getText().toString();
mPasswordRegister = mPasswordRegisterView.getText().toString();
mPasswordConfirmRegister = mPasswordConfirmRegisterView.getText().toString();
// These are all empty
Log.d(TAG, "Email : " + mEmailRegister);
Log.d(TAG, "Password : " + mPasswordRegister);
Log.d(TAG, "Confirm : " + mPasswordConfirmRegister);
}
});
}
}
如果您需要更多的代碼,請告訴我。
更改
到
,並定義的EditText(以下線)只有一次我其實是有最初。我想可能重新創建EditText對象,當點擊發生將允許我獲得值。沒有任何設置的喜悅。如果這是正確的方法,那麼我會改變我的代碼以反映這一點。我也會添加私人成員。 – RogerSmith