【问题标题】:how to get input from a pop up window如何从弹出窗口中获取输入
【发布时间】:2012-11-04 08:26:30
【问题描述】:
//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);
            }
        });

我想要的是在我单击父活动中的按钮时显示弹出窗口。弹出窗口有按钮,当点击按钮时它会执行一些功能。

【问题讨论】:

    标签: android popupwindow layout-inflater


    【解决方案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);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2023-03-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多