title: Use the same xml code from a popup in other similar pop-ups?
body: <p>I need to open a pop-up and then go to the other in my activity.
  I've already been able to do this, these two pop-ups are the same, but each of them assigns a value to a different variable.
  These two pop-ups are exactly the same, the only thing that changes is just the text.
  I would like to know if there is any way to make my code smaller in MainActivity, some way to use the same buttons for both pop-ups,
    Because in the future there will be 3 more pop-ups (equal to these)
  Here is the pop-ups xml and my activity code:</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="match_parent"
                android:layout_height="match_parent"
                android:background="@android:color/transparent"
                android:orientation="vertical"&gt;
  
  
      &lt;LinearLayout
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:layout_margin="10dp"
          android:background="#4d4dff"
          android:orientation="vertical"&gt;
  
          &lt;LinearLayout
              android:layout_width="match_parent"
              android:layout_height="match_parent"
              android:layout_margin="10dp"
              android:orientation="vertical"&gt;
  
              &lt;TextView
                  android:id="@+id/textoPoup1"
                  android:layout_width="match_parent"
                  android:layout_height="match_parent"
                  android:text="1 - Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua."
                  android:textColor="@android:color/white"
                  android:textSize="20dp" /&gt;
  
              &lt;LinearLayout
                  android:layout_width="match_parent"
                  android:layout_height="wrap_content"
                  android:orientation="horizontal"&gt;
  
                  &lt;Button
                      android:id="@+id/btnP1"
                      android:layout_width="0dp"
                      android:layout_height="wrap_content"
                      android:layout_weight="1"
                      android:text="0" /&gt;
  
                  &lt;Button
                      android:id="@+id/btnP2"
                      android:layout_width="0dp"
                      android:layout_height="wrap_content"
                      android:layout_weight="1"
                      android:text="50" /&gt;
  
                  &lt;Button
                      android:id="@+id/btnP3"
                      android:layout_width="0dp"
                      android:layout_height="wrap_content"
                      android:layout_weight="1"
                      android:text="100" /&gt;
              &lt;/LinearLayout&gt;
  
  
              &lt;LinearLayout
                  android:layout_width="match_parent"
                  android:layout_height="wrap_content"
                  android:orientation="horizontal"&gt;
  
  
                  &lt;Button
                      android:id="@+id/btnP4"
                      android:layout_width="0dp"
                      android:layout_height="wrap_content"
                      android:layout_weight="1"
                      android:text="150" /&gt;
  
                  &lt;Button
                      android:id="@+id/btnP5"
                      android:layout_width="0dp"
                      android:layout_height="wrap_content"
                      android:layout_weight="1"
                      android:text="200" /&gt;
  
  
                  &lt;Button
                      android:id="@+id/btnP6"
                      android:layout_width="0dp"
                      android:layout_height="wrap_content"
                      android:layout_weight="1"
                      android:text="250" /&gt;
              &lt;/LinearLayout&gt;
  
              &lt;Button
                  android:id="@+id/btnNext"
                  android:layout_width="match_parent"
                  android:layout_height="wrap_content"
                  android:text="Next Popup" /&gt;
          &lt;/LinearLayout&gt;
      &lt;/LinearLayout&gt;
  
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p>Other pop-up:</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="match_parent"
                android:layout_height="match_parent"
                android:background="@android:color/transparent"
                android:orientation="vertical"&gt;
  
  
      &lt;LinearLayout
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:layout_margin="10dp"
          android:background="#4d4dff"
          android:orientation="vertical"&gt;
  
          &lt;LinearLayout
              android:layout_width="match_parent"
              android:layout_height="match_parent"
              android:layout_margin="10dp"
              android:orientation="vertical"&gt;
  
              &lt;TextView
                  android:id="@+id/textoPoup1"
                  android:layout_width="match_parent"
                  android:layout_height="match_parent"
                  android:text="2 - Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi "
                  android:textColor="@android:color/white"
                  android:textSize="20dp" /&gt;
  
              &lt;LinearLayout
                  android:layout_width="match_parent"
                  android:layout_height="wrap_content"
                  android:orientation="horizontal"&gt;
  
                  &lt;Button
                      android:id="@+id/btnP1"
                      android:layout_width="0dp"
                      android:layout_height="wrap_content"
                      android:layout_weight="1"
                      android:text="0" /&gt;
  
                  &lt;Button
                      android:id="@+id/btnP2"
                      android:layout_width="0dp"
                      android:layout_height="wrap_content"
                      android:layout_weight="1"
                      android:text="50" /&gt;
  
                  &lt;Button
                      android:id="@+id/btnP3"
                      android:layout_width="0dp"
                      android:layout_height="wrap_content"
                      android:layout_weight="1"
                      android:text="100" /&gt;
              &lt;/LinearLayout&gt;
  
  
              &lt;LinearLayout
                  android:layout_width="match_parent"
                  android:layout_height="wrap_content"
                  android:orientation="horizontal"&gt;
  
  
                  &lt;Button
                      android:id="@+id/btnP4"
                      android:layout_width="0dp"
                      android:layout_height="wrap_content"
                      android:layout_weight="1"
                      android:text="150" /&gt;
  
                  &lt;Button
                      android:id="@+id/btnP5"
                      android:layout_width="0dp"
                      android:layout_height="wrap_content"
                      android:layout_weight="1"
                      android:text="200" /&gt;
  
  
                  &lt;Button
                      android:id="@+id/btnP6"
                      android:layout_width="0dp"
                      android:layout_height="wrap_content"
                      android:layout_weight="1"
                      android:text="250" /&gt;
              &lt;/LinearLayout&gt;
  
              &lt;Button
                  android:id="@+id/btnNext"
                  android:layout_width="match_parent"
                  android:layout_height="wrap_content"
                  android:text="Next Popup" /&gt;
          &lt;/LinearLayout&gt;
  
      &lt;/LinearLayout&gt;
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p>MainActivity:</p>
  
  <pre><code>    public class MainActivity extends AppCompatActivity implements View.OnClickListener
  {
      private Button btnPopup;
      private int value1;
      private int value2;
  
      @Override
      protected void onCreate(Bundle savedInstanceState)
      {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
  
          btnPopup = (Button) findViewById(R.id.btnPopup);
  
          btnPopup.setOnClickListener(this);
      }
  
      @Override
      public void onClick(View v)
      {
          if (v.getId() == R.id.btnPopup)
          {
  
              //-----------------------------------Second POPUP----------------------------------------------------
              LayoutInflater layoutInflater2 = (LayoutInflater) getBaseContext().getSystemService(LAYOUT_INFLATER_SERVICE);
              View popupView2 = layoutInflater2.inflate(R.layout.popup2, null);
              final PopupWindow popupWindow2 = new PopupWindow(popupView2,
                      ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
  
              final Button btn2P1 = (Button) popupView2.findViewById(R.id.btnP1);
              final Button btn2P2 = (Button) popupView2.findViewById(R.id.btnP2);
              final Button btn2P3 = (Button) popupView2.findViewById(R.id.btnP3);
              final Button btn2P4 = (Button) popupView2.findViewById(R.id.btnP4);
              final Button btn2P5 = (Button) popupView2.findViewById(R.id.btnP5);
              final Button btn2P6 = (Button) popupView2.findViewById(R.id.btnP6);
              final Button btn2Next = (Button) popupView2.findViewById(R.id.btnNext);
              btn2Next.setEnabled(false);
  
              btn2P1.setOnClickListener(new Button.OnClickListener()
              {
  
                  @Override
                  public void onClick(View v)
                  {
                      // TODO Auto-generated method stub
                      value2 = 0;
                      btn2P1.setEnabled(false);
                      btn2P2.setEnabled(true);
                      btn2P3.setEnabled(true);
                      btn2P4.setEnabled(true);
                      btn2P5.setEnabled(true);
                      btn2P6.setEnabled(true);
                      btn2Next.setEnabled(true);
                  }
              });
  
              btn2P2.setOnClickListener(new Button.OnClickListener()
              {
  
                  @Override
                  public void onClick(View v)
                  {
                      // TODO Auto-generated method stub
                      value2 = 50;
                      btn2P1.setEnabled(true);
                      btn2P2.setEnabled(false);
                      btn2P3.setEnabled(true);
                      btn2P4.setEnabled(true);
                      btn2P5.setEnabled(true);
                      btn2P6.setEnabled(true);
                      btn2Next.setEnabled(true);
                  }
              });
  
              btn2P3.setOnClickListener(new Button.OnClickListener()
              {
  
                  @Override
                  public void onClick(View v)
                  {
                      // TODO Auto-generated method stub
                      value2 = 100;
                      btn2P1.setEnabled(true);
                      btn2P2.setEnabled(true);
                      btn2P3.setEnabled(false);
                      btn2P4.setEnabled(true);
                      btn2P5.setEnabled(true);
                      btn2P6.setEnabled(true);
                      btn2Next.setEnabled(true);
                  }
              });
  
              btn2P4.setOnClickListener(new Button.OnClickListener()
              {
  
                  @Override
                  public void onClick(View v)
                  {
                      // TODO Auto-generated method stub
                      value2 = 150;
                      btn2P1.setEnabled(true);
                      btn2P2.setEnabled(true);
                      btn2P3.setEnabled(true);
                      btn2P4.setEnabled(false);
                      btn2P5.setEnabled(true);
                      btn2P6.setEnabled(true);
                      btn2Next.setEnabled(true);
                  }
              });
  
              btn2P5.setOnClickListener(new Button.OnClickListener()
              {
  
                  @Override
                  public void onClick(View v)
                  {
                      // TODO Auto-generated method stub
                      value2 = 200;
                      btn2P1.setEnabled(true);
                      btn2P2.setEnabled(true);
                      btn2P3.setEnabled(true);
                      btn2P4.setEnabled(true);
                      btn2P5.setEnabled(false);
                      btn2P6.setEnabled(true);
                      btn2Next.setEnabled(true);
                  }
              });
  
              btn2P6.setOnClickListener(new Button.OnClickListener()
              {
  
                  @Override
                  public void onClick(View v)
                  {
                      // TODO Auto-generated method stub
                      value2 = 250;
                      btn2P1.setEnabled(true);
                      btn2P2.setEnabled(true);
                      btn2P3.setEnabled(true);
                      btn2P4.setEnabled(true);
                      btn2P5.setEnabled(true);
                      btn2P6.setEnabled(false);
                      btn2Next.setEnabled(true);
                  }
              });
  
              btn2Next.setOnClickListener(new View.OnClickListener()
              {
                  @Override
                  public void onClick(View v)
                  {
                      popupWindow2.dismiss();
                      //popupWindow3.showAsDropDown(btnPopup, 50, -30);
                  }
              });
  
  
              //-----------------------------------First POPUP----------------------------------------------------
              LayoutInflater layoutInflater1 = (LayoutInflater) getBaseContext().getSystemService(LAYOUT_INFLATER_SERVICE);
              View popupView1 = layoutInflater1.inflate(R.layout.popup1, null);
              final PopupWindow popupWindow1 = new PopupWindow(popupView1,
                      ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
  
              final Button btnP1 = (Button) popupView1.findViewById(R.id.btnP1);
              final Button btnP2 = (Button) popupView1.findViewById(R.id.btnP2);
              final Button btnP3 = (Button) popupView1.findViewById(R.id.btnP3);
              final Button btnP4 = (Button) popupView1.findViewById(R.id.btnP4);
              final Button btnP5 = (Button) popupView1.findViewById(R.id.btnP5);
              final Button btnP6 = (Button) popupView1.findViewById(R.id.btnP6);
              final Button btnNext = (Button) popupView1.findViewById(R.id.btnNext);
              btnNext.setEnabled(false);
  
              btnP1.setOnClickListener(new Button.OnClickListener()
              {
  
                  @Override
                  public void onClick(View v)
                  {
                      // TODO Auto-generated method stub
                      value2 = 0;
                      btnP1.setEnabled(false);
                      btnP2.setEnabled(true);
                      btnP3.setEnabled(true);
                      btnP4.setEnabled(true);
                      btnP5.setEnabled(true);
                      btnP6.setEnabled(true);
                      btnNext.setEnabled(true);
                  }
              });
  
              btnP2.setOnClickListener(new Button.OnClickListener()
              {
  
                  @Override
                  public void onClick(View v)
                  {
                      // TODO Auto-generated method stub
                      value2 = 50;
                      btnP1.setEnabled(true);
                      btnP2.setEnabled(false);
                      btnP3.setEnabled(true);
                      btnP4.setEnabled(true);
                      btnP5.setEnabled(true);
                      btnP6.setEnabled(true);
                      btnNext.setEnabled(true);
                  }
              });
  
              btnP3.setOnClickListener(new Button.OnClickListener()
              {
  
                  @Override
                  public void onClick(View v)
                  {
                      // TODO Auto-generated method stub
                      value2 = 100;
                      btnP1.setEnabled(true);
                      btnP2.setEnabled(true);
                      btnP3.setEnabled(false);
                      btnP4.setEnabled(true);
                      btnP5.setEnabled(true);
                      btnP6.setEnabled(true);
                      btnNext.setEnabled(true);
                  }
              });
  
              btnP4.setOnClickListener(new Button.OnClickListener()
              {
  
                  @Override
                  public void onClick(View v)
                  {
                      // TODO Auto-generated method stub
                      value2 = 150;
                      btnP1.setEnabled(true);
                      btnP2.setEnabled(true);
                      btnP3.setEnabled(true);
                      btnP4.setEnabled(false);
                      btnP5.setEnabled(true);
         enter code here             btnP6.setEnabled(true);
                      btnNext.setEnabled(true);
                  }
              });
  
              btnP5.setOnClickListener(new Button.OnClickListener()
              {
  
                  @Override
                  public void onClick(View v)
                  {
                      // TODO Auto-generated method stub
                      value2 = 200;
                      btnP1.setEnabled(true);
                      btnP2.setEnabled(true);
                      btnP3.setEnabled(true);
                      btnP4.setEnabled(true);
                      btnP5.setEnabled(false);
                      btnP6.setEnabled(true);
                      btnNext.setEnabled(true);
                  }
              });
  
              btnP6.setOnClickListener(new Button.OnClickListener()
              {
  
                  @Override
                  public void onClick(View v)
                  {
                      // TODO Auto-generated method stub
                      value2 = 250;
                      btnP1.setEnabled(true);
                      btnP2.setEnabled(true);
                      btnP3.setEnabled(true);
                      btnP4.setEnabled(true);
                      btnP5.setEnabled(true);
                      btnP6.setEnabled(false);
                      btnNext.setEnabled(true);
                  }
              });
  
              btnNext.setOnClickListener(new View.OnClickListener()
              {
                  @Override
                  public void onClick(View v)
                  {
                      popupWindow1.dismiss();
                      popupWindow2.showAtLocation(btnPopup, Gravity.CENTER, 0, 0);
                  }
              });
              popupWindow1.showAtLocation(btnPopup, Gravity.CENTER, 0, 0);
          }
      }
  }
  </code></pre>