title: PopUp Window does not appear when i click
body: <p>I am quite new in android .I want a popup window in my application. i have a TextView and  a button in my activity_main.xml file, and a TextView and two Buttons in the popup.xml file
  here are these files</p>
  
  <pre><code>popup.xml file
  
  &lt;TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:id="@+id/popup_element"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent" &gt;
  
  &lt;TableRow
      android:id="@+id/tableRow1"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content" &gt;
  
  
  &lt;TextView
      android:id="@+id/txt1"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
  
      android:text="This is popoup" /&gt;
   &lt;/TableRow&gt;
  
  &lt;TableRow
      android:id="@+id/tableRow2"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content" &gt;
  
  
  &lt;Button
      android:id="@+id/Unpair"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:text="Unpair" /&gt;
  
  &lt;Button
      android:id="@+id/Cancel"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:text="cancel" /&gt;
  &lt;/TableRow&gt;
  &lt;/TableLayout&gt;
  </code></pre>
  
  <p>here is the activity_main.xml file</p>
  
  <pre><code>activity_main.xml
  
  &lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:tools="http://schemas.android.com/tools"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:paddingBottom="@dimen/activity_vertical_margin"
  android:paddingLeft="@dimen/activity_horizontal_margin"
  android:paddingRight="@dimen/activity_horizontal_margin"
  android:paddingTop="@dimen/activity_vertical_margin"
  tools:context=".MainActivity" &gt;
  
  &lt;TextView
      android:id="@+id/textView1"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:text="@string/hello_world" /&gt;
  
  &lt;Button
      android:id="@+id/btn1"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_below="@+id/textView1"
      android:layout_marginLeft="18dp"
      android:layout_marginTop="28dp"
      android:layout_toRightOf="@+id/textView1"
      android:text="Cick me" /&gt;
  
  &lt;/RelativeLayout&gt;
  </code></pre>
  
  <p>i want to display a popup window when i click the "click me" button. But popup doesn't appear when i do press the button</p>
  
  <pre><code>The java code
  
  package com.example.ctrckerapp;
  
  import android.os.Bundle;
  import android.widget.*;
  import android.app.Activity;
  import android.view.*;
  import android.content.*;
  public class MainActivity extends Activity {
  
  private PopupWindow  pw;
  private Button Cancel;
  private Button Unpair;
  private Button Click;
  View layout;
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
  
  
      Click=(Button)findViewById(R.id.btn1);
      Click.setOnClickListener(new View.OnClickListener() {  
            public void onClick(View v) 
            {
                initiatePopup();
            }
                 });
       try{
      Cancel.setOnClickListener(new View.OnClickListener() {  
            public void onClick(View v) 
            {
                pw.dismiss();
            }
             });
  
  
      layout.post(new Runnable(){
          public void run()
          {
          pw.showAtLocation(layout, Gravity.BOTTOM, 100, 700);
          }
      });
  
  }catch(Exception e){
      Toast.makeText(getApplicationContext(),      
   e.toString(),Toast.LENGTH_LONG).show();
  }
  
  
  }
  
  public void initiatePopup()
   {
      try{
      LayoutInflater inflater=       
  (LayoutInflater)MainActivity.this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
      layout=inflater.inflate(R.layout.popup, 
  (ViewGroup)findViewById(R.id.popup_element));
      pw=new PopupWindow(layout,300,670,true);
      Cancel =(Button)layout.findViewById(R.id.Cancel);
      Unpair=(Button)layout.findViewById(R.id.Unpair);
  
  
      }catch(Exception e){
          Toast.makeText(getApplicationContext(), 
  e.toString(),Toast.LENGTH_LONG).show();
      }
  
  }
   @Override
  public boolean onCreateOptionsMenu(Menu menu) {
      // Inflate the menu; this adds items to the action bar if it is present.
       getMenuInflater().inflate(R.menu.main, menu);
      return true;
  }
  
  }
  </code></pre>