我在創(chuàng)建登錄活動時遇到一些問題。即使我輸入了正確的用戶名(123456)和密碼(123456789)。我確保將 getText() 方法放在 onLogin 中,但我總是收到“登錄失敗”消息,因此我假設(shè)我沒有從 EditText 獲取任何數(shù)據(jù),因此我看不出出了什么問題。這個登錄java類: public class LoginActivity extends AppCompatActivity { private EditText UsernameEt; private EditText PasswordEt; AlertDialog alertDialog; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_login); UsernameEt=findViewById(R.id.username); PasswordEt=findViewById(R.id.password); alertDialog = new AlertDialog.Builder(this).create(); alertDialog.setTitle("Login Status"); } public void onLogin(View view) { String username = UsernameEt.getText().toString(); String password = PasswordEt.getText().toString(); String type = "login"; //BackgroundWorker backgroundWorker = new BackgroundWorker(this); //backgroundWorker.execute(type, username, password); if(username=="123456" && password=="123456789"){ alertDialog.setMessage("Login success"); alertDialog.show(); } else { alertDialog.setMessage("Login failed"); alertDialog.show(); } }}
我無法從 Edittext 獲取數(shù)據(jù)
寶慕林4294392
2023-09-13 15:21:34