title: How to create a popup window (PopupWindow) in Android
body: <p>To create a simple working PopupWindow, we need to do the following:</p>
  
  <p><strong>popup_example.xml:</strong></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
      &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
          android:orientation="vertical"
          android:padding="10dip"
          android:layout_width="fill_parent"
          android:layout_height="wrap_content"&gt;
  
          &lt;TextView         
              android:layout_width="fill_parent"
              android:layout_height="wrap_content"
              android:layout_marginTop="10dip"
              android:text="Test Pop-Up" /&gt;
  
      &lt;/LinearLayout&gt;
  </code></pre>
  
  <p><strong>Java code</strong>  </p>
  
  <pre><code>LayoutInflater inflater = (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
  
  PopupWindow pw = new PopupWindow(inflater.inflate(R.layout.popup_example, null, false),100,100, true);
  
  pw.showAtLocation(this.findViewById(R.id.main), Gravity.CENTER, 0, 0);
  </code></pre>
  
  <p>My requirement is that I need a </p>
  
  <pre><code>&lt;TEXTVIEW android:layout_height="wrap_content" android:layout_width="fill_parent" /&gt;
  </code></pre>
  
  <p>and a  </p>
  
  <pre><code>&lt;BUTTON android:id="@+id/end_data_send_button" android:text="Cancel"/&gt;
  </code></pre>
  
  <p>in my <code>popup_example.xml</code>.  How can I handle these two components in my Java code?</p>
  
  <p><img src="https://i.stack.imgur.com/F49MYm.png" alt="screenshot"></p>