//create inflater
final LayoutInflater inflater = (LayoutInflater) this
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
//create popupwindow
PopupWindow pw=new PopupWindow(inflater.inflate(R.layout.menu, (ViewGroup)findViewById(R.layout.dictionarylist)));
Button Menu = (Button) findViewById(R.id.Menu);
Menu.setOnClickListener(new Button.OnClickListener() {
public void onClick(View v) {
pw.showAtLocation(v, Gravity.CENTER, 0, 0);
pw.update(0, 0, 200, 250);
pw.setOutsideTouchable(false);
}
});
当我单击父活动中的按钮时,我想要显示弹出窗口。当点击按钮时,弹出窗口有按钮,它可以执行某些功能。
答案 0 :(得分:1)
你必须找到按钮的视图,然后像这样分配监听器:
View pview=inflater.inflate(R.layout.menu, (ViewGroup)findViewById(R.layout.dictionarylist));
Button Menu = (Button) pview.findViewById(R.id.Menu);
Menu.setOnClickListener(new Button.OnClickListener() {
public void onClick(View v) {
pw.showAtLocation(v, Gravity.CENTER, 0, 0);
pw.update(0, 0, 200, 250);
pw.setOutsideTouchable(false);
}
如果您还不喜欢这个,请初始化您的充气机:
Inflator inflator = LayoutInflater.from(this);