2

我在动态更改Android中的TextViewa 中的文本时遇到问题。PopupWindow我已经使用 a引用了TextView内部的元素,但文本没有更新。任何帮助将不胜感激!:)PopupWindowLayoutInflaterViewGroup

我的代码如下:

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

1 回答 1

5

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

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));
于 2011-09-04T15:21:42.103 回答