Cannot add clickListener for button in Popup
<p>I have popup in my android app. In popup I have button for closing popup with id="imbClosePopUp", but when I try to set to that button clickListener app crashs.</p>

<pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:orientation="vertical"
    android:layout_height="fill_parent"
    android:background="#AAAAAAAA"&gt;

    &lt;LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:gravity="right"
    android:layout_gravity="right"
    &gt;
    &lt;ImageButton
    android:id="@+id/imbClosePopUp"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="right"
    android:src="@drawable/close"
    &gt;&lt;/ImageButton&gt;
    &lt;/LinearLayout&gt;
    &lt;TextView
        android:text="CEKIRAJ OBAVEZNE KRITERIJUME"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"&gt;
    &lt;/TextView&gt; 
    &lt;TableLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
    &gt;
        &lt;TableRow&gt;
            &lt;CheckBox
                android:id="@+id/chkw"
                android:checked="true"
                android:text="cg"
            &gt;&lt;/CheckBox&gt;
            &lt;CheckBox
                android:id="@+id/chkq"
                android:checked="true"
                android:text="tv"
            &gt;&lt;/CheckBox&gt;
        &lt;/TableRow&gt;
    &lt;LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:gravity="right"
        android:layout_gravity="right"
&gt;
        &lt;Button
            android:id="@+id/btnSaveCrit"
            android:text="ok"
            android:layout_width="130dp"
            android:layout_height="wrap_content"
        &gt;
        &lt;/Button&gt;
    &lt;/LinearLayout&gt;
&lt;/LinearLayout&gt;
</code></pre>

<p>I set onclicklistener for button imbClosePopUp in function where I create Popup ( I create Popup on click some button ).</p>

<pre><code>  private OnClickListener AdditionalC = new OnClickListener() {
        public void onClick(View v) {
            LayoutInflater inflater = (LayoutInflater)
            roomate.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
          pw = new PopupWindow(
            inflater.inflate(R.layout.popup, null, false), 
            300, 
            300, 
            true);
         // The code below assumes that the root container has an id called 'main'
         pw.showAtLocation(roomate.findViewById(R.id.tbC), Gravity.CENTER, 0, 0); 

         ImageButton imbClosePopUp=(ImageButton)findViewById(R.id.imbClosePopUp);
         imbClosePopUp.setOnClickListener(ClosePopUp);


        }
    };
</code></pre>

<p>Does anybody know what is the ptoblem and how to colse popup ?</p>
