title: how to add view to new activity in ViewGroup
body: <p>ok so im trying to add a button/view to a new activity other than the one the Viewgroup is already in.
  here is my code so far:</p>
  
  <p>Src:</p>
  
  <pre><code>public class Main extends Activity {
      Button btn, btn1;
      LayoutInflater linflater;
      LinearLayout l;
      static int pos = 0;
  
      @Override
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.main);
  
          Button  ButtonBack = (Button) findViewById(R.id.dynamicoption);
          ButtonBack.setOnClickListener(new View.OnClickListener(){
  
                public void onClick(View v) {
                    // Perform action on click
  
                  startActivity(new Intent("com.nour.ImamKhomeini.DYNAMICOPTION"));
  
  
                }
  
            });
  
          btn = (Button) findViewById(R.id.Button01);
  
          l = (LinearLayout) findViewById(R.id.LinearLayout01);
          linflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
          btn.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                View myView = linflater.inflate(R.layout.dynamicoption, l, true);
                myView.setId(pos);
                pos++;
            }
          });
  
          btn = (Button) findViewById(R.id.Button01);
          btn1 = (Button) findViewById(R.id.Button02);
          l = (LinearLayout) findViewById(R.id.LinearLayout01);
          linflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
          btn.setOnClickListener(new myListener());
          btn1.setOnClickListener(new myListener1());
      }
  
      class myListener implements View.OnClickListener {
          @Override
          public void onClick(View v) {
              View myView = linflater.inflate(R.layout.dynamicoption, null);
              myView.setId(pos);
              pos++;
              l.addView(myView);
          }
      }
  
      class myListener1 implements View.OnClickListener {
          @Override
          public void onClick(View v) {
              if (pos != 0) {
                  pos--;
                  View myView = l.findViewById(pos);
                  l.removeView(myView);
              }
          }
      }
  }
  </code></pre>
  
  <p>And here are my xmls:</p>
  
  <p>Main:</p>
  
  <pre><code>&lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="fill_parent" android:layout_height="fill_parent"
      android:orientation="horizontal"&gt;
  
      &lt;Button android:id="@+id/Button01" android:background="@drawable/ic_launcher"
          android:layout_height="45dip" android:layout_width="45dip"&gt;&lt;/Button&gt;
  
      &lt;Button android:id="@+id/Button02" android:background="@drawable/ic_launcher"
          android:layout_height="45dip" android:layout_width="45dip"&gt;&lt;/Button&gt;
  
      &lt;LinearLayout android:id="@+id/LinearLayout01"
          android:layout_width="wrap_content" android:layout_height="wrap_content"
          android:orientation="vertical"&gt;&lt;/LinearLayout&gt;
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p>dynamicoption.xml:</p>
  
  <pre><code>&lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="wrap_content" android:layout_height="wrap_content"
      android:orientation="horizontal"&gt;
      &lt;EditText android:text="@+id/EditText01" android:id="@+id/EditText01"
          android:layout_width="wrap_content" android:layout_height="wrap_content"&gt;&lt;/EditText&gt;
      &lt;Button android:text="@+id/Button01" android:id="@+id/Button01"
          android:layout_width="wrap_content" android:layout_height="wrap_content"&gt;&lt;/Button&gt;
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p>Any Help is appreciated.
  Thank you.</p>