且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

从PopUpWindow越来越EDITTEXT输入

更新时间:2022-10-14 23:09:25

请尝试以下,而不是当您关闭弹出窗口:

 查看内容查看= 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.