【发布时间】:2013-04-02 17:30:51
【问题描述】:
当我显示一个包含 Button 的 PopupWindow 时,我无法点击他。执行 onclick,但不改变图形。
显示弹出窗口:
public void btn_friendsgame_newClick(View v) {
LayoutInflater layoutInflater =
(LayoutInflater)getBaseContext().getSystemService(LAYOUT_INFLATER_SERVICE);
View popupView = layoutInflater.inflate(R.layout.custom_dialog, null);
RelativeLayout content = (RelativeLayout) popupView.findViewById(R.id.layout_content);
Button b = new Button(this); // THIS BUTTON CAN'T CLICK!
b.setText("Test");
b.setLayoutParams(new LayoutParams(
ViewGroup.LayoutParams.WRAP_CONTENT,
ViewGroup.LayoutParams.WRAP_CONTENT));
content.addView(b);
final PopupWindow popupWindow = new PopupWindow(popupView,
LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
popupWindow.showAtLocation(this.findViewById(R.id.main), Gravity.CENTER, 0, 0);
Button close = (Button) popupView.findViewById(R.id.btn_popup_settings);
close.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
popupWindow.dismiss();
}
});
custom_dialog.xml:http://pastebin.com/dLivuE17
如何修复?
【问题讨论】:
-
这是
AlertDialog框吗?或什么样的弹出窗口?为什么不使用包含最多三个可以编码的按钮的警报对话框构建器。
标签: android button click popupwindow