从PopUpWindow越来越EDITTEXT输入 [英] getting editText input from PopUpWindow
问题描述
我不知道我怎么能拿从EDITTEXT框中输入一个popupwindow。我试过2种方式。一个具有布局充气,一个没有,但我要么得到或空,即使我输入的东西成箱
这其中一个返回了
//获取用户名和密码输入
查看inflatedView = getLayoutInflater()膨胀(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); 。最后弦乐usernameString = usernameInput.getText()的toString();
。最后弦乐passwordString = passwordInput.getText()的toString();
这其中一个返回空值:
//获取用户名和密码输入
的EditText usernameInput =(EditText上)findViewById(R.id.username_login_input);
的EditText passwordInput =(EditText上)findViewById(R.id.password_login_input); 。最后弦乐usernameString = usernameInput.getText()的toString();
。最后弦乐passwordString = passwordInput.getText()的toString();
我想从其中无法从活动产生的login_popup.xml得到它
这是其中code是
修改
LayoutInflater layoutInflater =
(LayoutInflater)getBaseContext()getSystemService(LAYOUT_INFLATER_SERVICE)。
查看popupView = layoutInflater.inflate(R.layout.login_popup,NULL);
PPW =新PopupWindow(popupView,LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT,真正的);
ViewGroup中parentLayout =(ViewGroup中)findViewById(R.id.title_page_layout);
//设置位置和弹出窗口的大小
ppw.showAtLocation(parentLayout,Gravity.CENTER,10,20);
请尝试以下,而不是当您关闭弹出窗口:
查看内容查看= ppw.getContentView();
的EditText usernameInput =(EditText上)contentView.findViewById(R.id.username_login_input);
的EditText passwordInput =(EditText上)contentView.findViewById(R.id.password_login_input);
。最后弦乐usernameString = usernameInput.getText()的toString();
。最后弦乐passwordString = passwordInput.getText()的toString();
我觉得你目前的做法是夸大新的观点,而不是从弹出的窗口中获取现有的意见。
I was wondering how I could get the input from an editText box in a popupwindow. I tried 2 ways. One with a layout inflator and one without but I either get "" or null even though i typed something into the box
This one returns the "" :
// 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();
This one returns 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();
I am trying to get it from login_popup.xml which is not generated from an activity
This is where the code is from
EDIT
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);
Try the following instead when your popup window is closed:
View contentView = ppw.getContentView();
EditText usernameInput = (EditText) contentView.findViewById(R.id.username_login_input);
EditText passwordInput = (EditText) contentView.findViewById(R.id.password_login_input);
final String usernameString = usernameInput.getText().toString();
final String passwordString = passwordInput.getText().toString();
I think your current approach is inflating new views, rather than obtaining the existing views from the popup window.
这篇关于从PopUpWindow越来越EDITTEXT输入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!