如何从弹出窗口获取输入

Nas*_*Nas 6 android popupwindow layout-inflater

//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);
            }
        });
Run Code Online (Sandbox Code Playgroud)

我想要的是当我单击父活动中的按钮时显示弹出窗口.当弹出按钮时,弹出窗口有按钮,它可以执行某些功能.

在此输入图像描述

Anu*_*kur 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);
            }
Run Code Online (Sandbox Code Playgroud)

如果您还没有这样初始化您的充气机:

Inflator inflator = LayoutInflater.from(this);
Run Code Online (Sandbox Code Playgroud)