how to handle onclick event of button inside popup window in android

前端 未结 4 1106
天命终不由人
天命终不由人 2021-01-02 11:01

In my application, I have a button initially on the screen, and in onclick of the button, a popup window should open. In the popup window, I have an imagebutton

4条回答
  •  甜味超标
    2021-01-02 11:35

    You have to find the button into the Popup view:

    View pview = inflater.inflate(R.layout.popup_example,(ViewGroup)findViewById(R.layout.main));
    PopupWindow pw = new PopupWindow(pview);
                pw.showAtLocation(v, Gravity.LEFT,0,0);
                pw.update(8,-70,150,270);
    
                  //if onclick written here, it gives null pointer exception.
                ImageButton img=(ImageButton)pview.findViewById(R.id.home);
                img.setOnClickListener(new OnClickListener()
                {
                    public void onClick(View v)
                    {
                        Intent.....
                    }
            });
    

提交回复
热议问题