Can't edit an edittext in a popup window without dismissing and recalling it first

馋奶兔 提交于 2020-01-06 05:41:08

问题


I am using a popup window to display some information and have an edit button that allows that information to be changed. I am loading all textviews, buttons and edittext fields and hiding/showing them as needed. The edittext fields are not letting me edit them. I have tried the below suggestion about setting focusable to true, but that isn't working. Any other suggestions?

Tried this: EditText On A Popup Window

EDIT: Below is part of my code. I've just included the parts for initializing the edittext and showing the popup contents since everything else is working, just not the edittext. I am using a tablelayout, and when the user clicks a row, the popup window displays. Keep in mind I'm still pretty new to Java and Android!

EDIT #2: The softkeyboard was not showing when the edittext was selected, but now it will show if I dismiss the popup once and then call it again. I then tried forcing the softkeyboard to display, and it showed behind the popup (another problem). I was able to select the number 1 since it was barely showing behind the popup window, but it didn't seem to work either. The fix was the same here: dismiss the popup window and recall it. So my remaining problem is being able to type into the edittext without having to dismiss the popup once and recall it. As such, I am changing the title of this question.

row1.setOnClickListener(new OnClickListener() {

@Override
public void onClick(View v) {

    final EditText pwETBrand = (EditText) vPopUp.findViewById(R.id.et_editbrand);

    if (!infoClick) {
        infoClick = true;

        // Popup elements initialized earlier
        pwInfo.showAtLocation(llInfo, Gravity.CENTER_HORIZONTAL | Gravity.CENTER_VERTICAL, 0, 0);
        pwInfo.update(0, 0, llMain.getWidth()-50, llMain.getHeight()-100);
        pwInfo.setFocusable(true);

....

        // Hide some elements initially until "EDIT" button is pressed
        pwETBrand.setVisibility(View.INVISIBLE);

....

        // When EDIT button is pressed, hide default elements, and show edit elements
        pwEdit.setOnClickListener(new OnClickListener() {
            public void onClick(View v2) {
                pwETBrand.setVisivility(View.VISIBLE);
                // Other element settings go here
                pwInfo.setFocusable(true);
            }
        )};

....

    }
}

回答1:


I have implemented a solution, though it may not be the best solution. I have set a boolean field at the class initialization that checks if the popupwindow has ever been called. If it has not yet been called, then it will immediately dismiss the popupwindow and re-open it since my problem is in the popupwindow initialization.

    pwInfo.showAtLocation(llInfo, Gravity.CENTER_HORIZONTAL | Gravity.CENTER_VERTICAL, 0, 0);
    pwInfo.update(0, 0, llMain.getWidth()-50, llMain.getHeight()-100);
    pwInfo.setFocusable(true);

    if (pwFirst) {
        pwFirst = false;
        pwInfo.dismiss();
        pwInfo.showAtLocation(llInfo, Gravity.CENTER_HORIZONTAL | Gravity.CENTER_VERTICAL, 0, 0);
        pwInfo.update(0, 0, llMain.getWidth()-50, llMain.getHeight()-100);
        pwInfo.setFocusable(true);
    }

Not the best solution, but it works.




回答2:


Try this,

final PopupWindow popupWindow = new PopupWindow(popupView,LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT,true);

works for me.




回答3:


Use Below Link's Code for that, it may help you.

Popup With Edittext




回答4:


Whenever you create a PopupWindow you must put true in focusable like that :

 PopupWindow(View contentView, int width, int height, boolean focusable) 

  final PopupWindow popupWindow = new PopupWindow(popupView,LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT,true); 

good luck



来源:https://stackoverflow.com/questions/10989995/cant-edit-an-edittext-in-a-popup-window-without-dismissing-and-recalling-it-fir

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!