title: How to define layout in a PopupWindow from an xml file, when PopupWindow method is called from a separate class
body: <p>I'd like to be able to define layout in a PopupWindow from an xml file when the PopupWindow method is called from a separate class. Below code works as needed EXCEPT that layout is pulled from the java file and not the xml file.I do not know how to properly access xml layout and implement in the PopupWindow in this situation, or if this is possible. Advice and specific suggestions are appreciated. Thanks. </p>
  
  <p><strong>showPopup.java</strong></p>
  
  <pre><code>public class showPopup {
  Context ctx;
  Button btnDismiss;
  
  public showPopup(Context ctx){
      this.ctx = ctx;     
  }
  
  public void onCreateView(LayoutInflater layoutInflater, ViewGroup container) {
      View layout = layoutInflater.inflate(R.layout.popup_layout, null);   
      btnDismiss = (Button) layout.findViewById(R.id.btndismissxml);
  }
  
  public void goJoe(View parent){ 
      final PopupWindow popup = new PopupWindow(ctx);
  
      btnDismiss = new Button (ctx);
      btnDismiss.setText("Text is from showPopup.java");
  
      popup.setContentView(btnDismiss);
      popup.setWidth(400);
      popup.setHeight(580);
      popup.showAtLocation(parent, Gravity.CENTER_HORIZONTAL, 10, 10);        
  
      btnDismiss.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View v) {
              popup.dismiss();    
          }
      });
    }
  }
  </code></pre>
  
  <p><strong>Tab3Fragment.java</strong></p>
  
  <pre><code>public class Tab3Fragment extends Fragment implements OnClickListener{
  Button btnPopup;
  
  @Override
  public View onCreateView(LayoutInflater inflater, ViewGroup containerGroup, Bundle savedInstanceState) {    
      View v = inflater.inflate(R.layout.tab3_fragment, containerGroup, false);   
      btnPopup = (Button)v.findViewById(R.id.btnPopupxml);
      btnPopup.setOnClickListener(this);
      return v;
  }
  //@Override
  public void onViewCreated(View v) {
      btnPopup = (Button)v.findViewById(R.id.btnPopupxml);
      btnPopup.setOnClickListener(this);
  }
  @Override
  public void onClick(View parent) {
      new showPopup(getActivity().getApplicationContext()).goJoe(parent); 
    }
  }
  </code></pre>
  
  <p><strong>popup_layout.xml</strong></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="wrap_content" 
  android:layout_height="fill_parent"
  android:id="@+id/layout"&gt;
  
  &lt;Button android:layout_height="wrap_content"
      android:layout_alignParentBottom="true"
      android:layout_width="wrap_content" 
      android:id="@+id/btndismissxml"
      android:text="Text is from popup_layout.xml"&gt;&lt;/Button&gt;
  &lt;/RelativeLayout&gt;
  </code></pre>
  
  <p><strong>Update (1835, Dec-11):</strong>
  This is a draft popup. There will be several of these servicing user editable dropdown fields in the application.</p>
  
  <p><img src="https://i.stack.imgur.com/oAP89.png" alt="enter image description here"></p>