简体   繁体   English

如何从弹出窗口获取输入

[英]how to get input from a pop up window

//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);
            }
        });

What i want is to show the popup window when i click the button in the parent activity. 我想要的是当我单击父活动中的按钮时显示弹出窗口。 The popup window have buttons when onclick the button it do some functions. 当弹出按钮时,弹出窗口有按钮,它可以执行某些功能。

在此输入图像描述

You have to find the view of the button and then assign the listener to it like this: 你必须找到按钮的视图,然后像这样分配监听器:

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

Also initialize your inflator if you haven't already like this: 如果您还不喜欢这个,请初始化您的充气机:

Inflator inflator = LayoutInflater.from(this);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM