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

前端 未结 4 1119
天命终不由人
天命终不由人 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:32

    This will not give error in Inflater and work properly:

        LayoutInflater layoutInflater = getLayoutInflater();
    
    
          View pview = layoutInflater.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.....
                }
        });
    

提交回复
热议问题