title: Android - Programatically changing Popup Window's layout
body: <p>I have a <code>PopupWindow</code> which finally decides to follow my command and show itself after null error(certainly not my mistake in forgetting to initialize some value).</p>
  
  <p>Here's the xml file for the <code>PopupWindow</code></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:id="@+id/popup_handphone_MainLayout"
      android:layout_width="match_parent" android:layout_height="match_parent"&gt;
  
      &lt;RelativeLayout
          android:id="@+id/popup_handphone_Wrapper"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:background="@drawable/popupkodehp"&gt;
  
          &lt;TextView
              android:id="@+id/popup_handphone_text"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:layout_marginTop="10dp"
              android:gravity="center"
              android:textColor="@color/textColor"
              android:text="@string/popupPhoneMessage"/&gt;
  
          &lt;RelativeLayout
              android:id="@+id/popup_handphone_functionalities"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:layout_below="@+id/popup_handphone_text"
              android:layout_marginTop="15dp"&gt;
  
              &lt;EditText
                  android:id="@+id/popup_handphone_phoneNumber"
                  android:layout_width="match_parent"
                  android:layout_height="wrap_content"
                  android:hint="Phone Number"
                  android:textColorHint="@color/textColor" /&gt;
  
              &lt;EditText
                  android:id="@+id/popup_handphone_phoneNumberConfirm"
                  android:layout_width="match_parent"
                  android:layout_height="wrap_content"
                  android:layout_below="@+id/popup_handphone_phoneNumber"
                  android:layout_marginTop="10dp"
                  android:hint="Retype Phone Number"
                  android:textColorHint="@color/textColor"/&gt;
  
              &lt;Button
                  android:layout_width="match_parent"
                  android:layout_height="wrap_content"
                  android:layout_below="@+id/popup_handphone_phoneNumberConfirm"
                  android:layout_marginTop="20dp"
                  android:minHeight="20dp"
                  android:text="Send Code"
                  android:textColor="@color/textColor"/&gt;
  
          &lt;/RelativeLayout&gt;
  
      &lt;/RelativeLayout&gt;
  
  &lt;/RelativeLayout&gt;
  </code></pre>
  
  <p>Here's the code of the <code>PopupWindow</code> I made with the help of anonymous and amazing people all over Google</p>
  
  <pre><code>View.OnClickListener phoneReinputHandler = new View.OnClickListener() {
  
          public void onClick(View arg0) {
              /*Intent intent = new Intent(SignupStepTwoActivity.this, PopupHandphone.class);
              backDim = (RelativeLayout) findViewById(R.id.bac_dim_layout);
              //backDim.setVisibility(View.VISIBLE);
              startActivity(intent);*/
  
              mainLayout = (RelativeLayout)findViewById(R.id.activity_signup_step_two_mainLayout);
  
              int width = displayMetrics.widthPixels;
              int height = displayMetrics.heightPixels;
              inflater = (LayoutInflater)getBaseContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
  /*            View popupLayoutInflater = inflater.inflate(R.layout.popup_handphone, mainLayout);
  
              RelativeLayout popupFunctionalitiesWrapper = (RelativeLayout)popupLayoutInflater.findViewById(R.id.popup_handphone_functionalities);
              int popupFunctionalitiesWrapperHeight = layoutResize.height(70, displayMetrics);
              RelativeLayout.LayoutParams popupFunctionalitiesWrapperParams = (RelativeLayout.LayoutParams)popupFunctionalitiesWrapper.getLayoutParams();
              popupFunctionalitiesWrapperParams.height = popupFunctionalitiesWrapperHeight;
  */
              PopupWindow pw = new PopupWindow(
                      inflater.inflate(R.layout.popup_handphone, null, false),
                      (int)(width * .8),
                      (int)(height*.35),
                      true);
              pw.setBackgroundDrawable(new ColorDrawable(getResources().getColor(android.R.color.transparent)));
              pw.setOutsideTouchable(true);
  
              pw.showAtLocation(mainLayout, Gravity.CENTER, 0, 0);
  
          }
      };
  </code></pre>
  
  <p>The second commented part is a failed attempt to set the layout element's height. It shows itself on the main layout too, as in, the whole <code>PopupWindow</code> layout lay on top of the class' layout.</p>
  
  <p>How to programatically customize the <code>PopupWindow</code> layout I made from the class' layout I'm at?</p>