没有解雇并首先回顾它无法编辑在弹出窗口中一个EditText [英] Can't edit an edittext in a popup window without dismissing and recalling it first

查看:149
本文介绍了没有解雇并首先回顾它无法编辑在弹出窗口中一个EditText的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是弹出窗口显示一些信息,并有一个编辑按钮,它允许被改变的信息。我加载所有textviews,按钮和领域的EditText并隐藏/显示他们需要。该领域的EditText不会让我编辑它们。我曾尝试有关设置可聚焦到真正的以下建议,但不工作。任何其他建议?

试过这个:的EditText上的弹出窗口

编辑:下面是我的code的一部分。我刚刚包含了初始化的EditText和展示,因为所有东西都正常,只是没有EditText上弹出的内容部分。我使用的是tablelayout,当用户点击一排,在弹出的窗口显示。请记住我依然pretty对Java和Android!

编辑#2:softkeyboard不显示时选择了EditText上,但现在如果我曾经解雇弹出,然后再次调用它,它就会显示出来。然后我试图迫使softkeyboard显示,而事实证明,在弹出的(另一个问题)的后面。我能选择1号,因为它几乎没有显示弹出窗口的后面,但它似乎没有任何工作。此修复程序是一样的位置:关闭该弹出窗口,并调用它。 所以,我剩下的问题是能够无需解雇后弹出并调用它输入到的EditText。因此,我改变了这个问题的标题。

  row1.setOnClickListener(新OnClickListener(){@覆盖
公共无效的onClick(视图v){    最终的EditText pwETBrand =(EditText上)vPopUp.findViewById(R.id.et_editbrand);    如果(!infoClick){
        infoClick = TRUE;        //弹出元素较早初始化
        pwInfo.showAtLocation(llInfo,Gravity.CENTER_HORIZONTAL | Gravity.CENTER_VERTICAL,0,0);
        pwInfo.update(0,0,llMain.getWidth() - 50,llMain.getHeight() - 100);
        pwInfo.setFocusable(真);

...

  //隐藏一些元素最初直到编辑按钮是pressed
        pwETBrand.setVisibility(View.INVISIBLE);

...

  //当编辑按钮被pressed,默认情况下隐藏的元素,并显示编辑元素
        pwEdit.setOnClickListener(新OnClickListener(){
            公共无效的onClick(查看V2){
                pwETBrand.setVisivility(View.VISIBLE);
                //其他元素设置何去何从
                pwInfo.setFocusable(真);
            }
        )};

...

 }
}


解决方案

我实现了一个解决方案,但它可能不是最好的解决方案。我已经在类的初始化,检查是否popupwindow曾经被称为设置一个布尔字段。如果还没有被调用,那么它会立即解雇popupwindow既然我的问题是在popupwindow初始化重新打开它。

  pwInfo.showAtLocation(llInfo,Gravity.CENTER_HORIZONTAL | Gravity.CENTER_VERTICAL,0,0);
    pwInfo.update(0,0,llMain.getWidth() - 50,llMain.getHeight() - 100);
    pwInfo.setFocusable(真);    如果(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(真);
    }

不是最好的解决方案,但它的工作原理。

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);
            }
        )};

....

    }
}

解决方案

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.

这篇关于没有解雇并首先回顾它无法编辑在弹出窗口中一个EditText的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆