我正在做一個簡單的登錄應用程序,我需要將用戶ID傳遞到後續屏幕。但是,我沒有獲得用戶名字段的變量。編輯文本getText()。toString()返回空白
public static String user;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
EditText username = (EditText)findViewById(R.id.etUserName);
EditText password = (EditText)findViewById(R.id.etPwd);
Button blogin = (Button)findViewById(R.id.bLogin);
user = username.getText().toString();// Here user variable is blank!!!!!!!!!!!!!!!
請幫助!
它將在onCreate()方法總是空白,你需要把它寫在按鈕的單擊事件,那麼只有你可以得到價值 – Vickyexpert
好。對於測試用例加上'username.setText(「我sourav」 );''用戶'之前' –
[獲取編輯文本字段的值]的可能副本(http://stackoverflow.com/questions/4531396/get-value-of-a-edit-text-field) – Veer3383