title: How to dynamically add new tab onclick and populate pre-designed fragment to that?
body: <p>I am creating an application which requires tabs. I created a Fragment with a design in it. How could i dynamically add tabs like adding tabs in chrome and removing exactly like chrome tabs and populate the newly added tab with the fragment i designed. </p>
  
  <p>My Activity code is:</p>
  
  <pre><code>public class MainActivity extends AppCompatActivity {
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
          FragmentManager fragmentManager = getFragmentManager();
          FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
          POSFragment hello = new POSFragment();
          fragmentTransaction.add(R.id.fragment_container, hello, "HELLO");
          fragmentTransaction.commit();
      }
  }
  </code></pre>
  
  <p>FRAGMENT CODE:</p>
  
  <pre><code>public class POSFragment extends Fragment {
      @Override
      public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
          /** Inflating the layout for this fragment **/
          View v = inflater.inflate(R.layout.posfragment, null);
          return v;
      }
  }
  </code></pre>
  
  <p>Main activity XML:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:app="http://schemas.android.com/apk/res-auto"
      xmlns:tools="http://schemas.android.com/tools"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      tools:context="com.eazypos.app.MainActivity"&gt;
  
      &lt;LinearLayout
          android:id="@+id/fragment_container"
          android:layout_width="fill_parent"
          android:layout_height="wrap_content"
          android:orientation="vertical"&gt;&lt;/LinearLayout&gt;
  &lt;/RelativeLayout&gt;
  </code></pre>
  
  <p>Fragment XML:</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="match_parent"
      android:layout_height="match_parent"
      xmlns:app="http://schemas.android.com/apk/res-auto"&gt;
  
      &lt;TextView
          android:id="@+id/textView"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_alignParentStart="true"
          android:layout_alignParentTop="true"
          android:layout_marginStart="416dp"
          android:layout_marginTop="230dp"
          android:text="Hello" /&gt;
  &lt;/RelativeLayout&gt;
  </code></pre>
  
  <p>Is there any forum or link i can research on.. or any quick code snippet I can work on. I am very new to this..</p>