BGM*_*BGM 2 java android popupwindow textview viewgroup
我有动态改变文本的问题TextView在PopupWindowAndroid中.我已使用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();
}
}
Run Code Online (Sandbox Code Playgroud)
问题是:您要将布局膨胀两次,而不是:
recording_text = (TextView) layout.findViewById(R.id.recording_text);
Run Code Online (Sandbox Code Playgroud)
做这个:
recording_text = (TextView) pw.getContentView().
findViewById(R.id.recording_text);
Run Code Online (Sandbox Code Playgroud)
而且,你根本不需要这一行:
View layout = inflater.inflate(R.layout.popup_recording,
(ViewGroup) findViewById(R.id.popup_element));
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1956 次 |
| 最近记录: |