我想知道如何从弹出窗口中的编辑文本框中获取输入。我尝试了两种方法。一个带有布局充气机,一个没有,但即使我在框中输入了一些内容,我也会得到“”或 null
这个返回 "" :
// get the username and password inputs
View inflatedView = getLayoutInflater().inflate(R.layout.login_popup, null);
EditText usernameInput = (EditText) inflatedView.findViewById(R.id.username_login_input);
EditText passwordInput = (EditText) inflatedView.findViewById(R.id.password_login_input);
final String usernameString = usernameInput.getText().toString();
final String passwordString = passwordInput.getText().toString();
这个返回 null :
// get the username and password inputs
EditText usernameInput = (EditText) findViewById(R.id.username_login_input);
EditText passwordInput = (EditText) findViewById(R.id.password_login_input);
final String usernameString = usernameInput.getText().toString();
final String passwordString = passwordInput.getText().toString();
我正在尝试从不是从活动生成的 login_popup.xml 获取它
这是代码的来源
编辑
LayoutInflater layoutInflater =
(LayoutInflater) getBaseContext().getSystemService(LAYOUT_INFLATER_SERVICE);
View popupView = layoutInflater.inflate(R.layout.login_popup, null);
ppw = new PopupWindow(popupView, LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, true);
ViewGroup parentLayout = (ViewGroup) findViewById(R.id.title_page_layout);
// set the position and size of popup
ppw.showAtLocation(parentLayout, Gravity.CENTER, 10, 20);