Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/395.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 更改PopupWindow中TextView的文本不工作_Java_Android_Textview_Popupwindow_Viewgroup - Fatal编程技术网

Java 更改PopupWindow中TextView的文本不工作

Java 更改PopupWindow中TextView的文本不工作,java,android,textview,popupwindow,viewgroup,Java,Android,Textview,Popupwindow,Viewgroup,我在Android的弹出窗口中动态更改TextView中的文本时遇到问题。我使用LayoutFlater和ViewGroup引用了PopupWindow中的TextView元素,但文本没有更新。非常感谢您的帮助 我的代码如下: private void popupWindow() { try { LayoutInflater inflater = (LayoutInflater) SwingSpeed.this .g

我在Android的弹出窗口中动态更改TextView中的文本时遇到问题。我使用LayoutFlater和ViewGroup引用了PopupWindow中的TextView元素,但文本没有更新。非常感谢您的帮助

我的代码如下:

private void popupWindow() {
        try {
            LayoutInflater inflater = (LayoutInflater) SwingSpeed.this
                    .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            View layout = inflater.inflate(R.layout.popup_recording,
                    (ViewGroup) findViewById(R.id.popup_element));
            pw = new PopupWindow(inflater.inflate(R.layout.popup_recording,
                    null, false), 480, 800, true);
            pw.showAtLocation(findViewById(R.id.swingspeed), Gravity.CENTER, 0,
                    0);
            recording_text = (TextView) layout
                    .findViewById(R.id.recording_text);
            recording_text.setText("Recording"); //Update the TextView  
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

问题是:您将布局膨胀了两次, 而不是:

recording_text = (TextView) layout.findViewById(R.id.recording_text);
这样做:

recording_text = (TextView) pw.getContentView().
                 findViewById(R.id.recording_text);
而且,您根本不需要这一行:

View layout = inflater.inflate(R.layout.popup_recording,
                (ViewGroup) findViewById(R.id.popup_element));