title: Passing a data from Activity to Tabbed Layout Fragment?
body: <p>I have two Activities. One is normal Activity which contains listview and second one is Tabbed Layout which it have two tabs. One is "Description" tab and another one is "Sample Code" tab.</p>
  
  <p>I have created two seperate fragments for each namely "OneFragment" and "TwoFragment". All i need is when user click an Item from my normal Activity, this item will be stored in string and that string should be passed to Tabbed layout and it should be showed in OneFragment ie., "Description" tab </p>
  
  <p>(Ex). My List Contains {"Android","Studio"} if user clicks Android,this text should pass to description tab and showed the text using TextView. please help me. Here i include my respective codes..</p>
  
  <p><strong>NormalActivity - >ListActi.java</strong></p>
  
  <pre><code>   @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_list);
          lv = (ListView) findViewById(R.id.listView);
          final List&lt;String&gt; ListElementsArrayList = new ArrayList&lt;String&gt;(Arrays.asList(listElements));
          final ArrayAdapter&lt;String&gt; adapter = new ArrayAdapter&lt;String&gt;
                  (getApplicationContext(), android.R.layout.simple_list_item_1, ListElementsArrayList);
          lv.setAdapter(adapter);
          lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
              @Override
              public void onItemClick(AdapterView&lt;?&gt; parent, View view, int position, long id) {
                  //Toast.makeText(getApplicationContext(), listElements[position],Toast.LENGTH_LONG).show();
                  s = listElements[position];
                  if(position == 1){
                      s = listElements[position];
                      Bundle bundle = new Bundle();
                      bundle.putString("ClickedItem", listElements[position]);
                      OneFragment fragobj = new OneFragment();
                      TwoFragment fag = new TwoFragment();
                      fragobj.setArguments(bundle);
                      fag.setArguments(bundle);
                      Intent i = new Intent(getApplicationContext(),BothLay.class);
                      startActivity(i);
                  }
             }
          });
      }
  }
  </code></pre>
  
  <p><strong>TabActivity - > BothLay</strong></p>
  
  <pre><code>public class BothLay extends AppCompatActivity  {
      private Toolbar toolbar;
      private TabLayout tabLayout;
      private ViewPager viewPager;
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_both_lay);
          viewPager = (ViewPager) findViewById(R.id.viewpager);
          setupViewPager(viewPager);
          tabLayout = (TabLayout) findViewById(R.id.tabs);
          tabLayout.setupWithViewPager(viewPager);
      }
      private void setupViewPager(ViewPager viewPager) {
          ViewPagerAdapter adapter = new ViewPagerAdapter(getSupportFragmentManager());
          adapter.addFragment(new OneFragment(), "Description");
          adapter.addFragment(new TwoFragment(), "Sample Code");
          viewPager.setAdapter(adapter);
      }
      class ViewPagerAdapter extends FragmentPagerAdapter {
          private final List&lt;Fragment&gt; mFragmentList = new ArrayList&lt;&gt;();
          private final List&lt;String&gt; mFragmentTitleList = new ArrayList&lt;&gt;();
          public ViewPagerAdapter(FragmentManager manager) {
              super(manager);
          }
          @Override
          public Fragment getItem(int position) {
              return mFragmentList.get(position);
          }
          @Override
          public int getCount(){
              return mFragmentList.size();
          }
          public void addFragment(Fragment fragment, String title) {
              mFragmentList.add(fragment);
              mFragmentTitleList.add(title);
          }
          @Override
          public CharSequence getPageTitle(int position) {
              return mFragmentTitleList.get(position);
          }
      }
  }
  </code></pre>
  
  <p><strong>Decription tab - >OneFragment</strong> (All i need is pass a data from Normal Activity to this Fragment)</p>
  
  <pre><code>public class OneFragment extends Fragment{
      String strtext = "Ajay";
      public OneFragment() {
          // Required empty public constructor
      }
      @Override
      public void onCreate(Bundle savedInstanceState) {
  
          super.onCreate(savedInstanceState);
      }
      @Override
      public View onCreateView(LayoutInflater inflater, ViewGroup container,
                               Bundle savedInstanceState) {
  
          View rootview = inflater.inflate(R.layout.fragment_one, container, false);
          TextView textView = (TextView) rootview.findViewById(R.id.t1);
          //strtext = getIntent().getStringExtra("ClickedItem"); //this doesn't work  
          textView.setText(strtext);
          return rootview;
      }
  }
  </code></pre>
  
  <p><strong>Sample Code tab ->Twofragment</strong></p>
  
  <pre><code>public class TwoFragment extends Fragment{
      public TwoFragment() {
          // Required empty public constructor
      }
      @Override
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
      }
      @Override
      public View onCreateView(LayoutInflater inflater, ViewGroup container,
                               Bundle savedInstanceState) {
          return inflater.inflate(R.layout.fragment_two, container, false);
      }
  
  }
  </code></pre>