title: how to add data inside tablayout which is created through JSON?
body: <p>I am trying to make a dynamic tablayout. I am getting values from json and i am able to make tabs but i want to add values(List) inside those tabs.the Values(List) is also in json format. I am not getting how can i achieve it.</p>
  
  <p>this is my json format </p>
  
  <pre><code>{ "Categories": [ { "cat_id": "17", "cat_name": "Bridal Costume ", "sub_categories": [] }, { "cat_id": "18", "cat_name": "Jewellery", "sub_categories": [] }, { "cat_id": "19", "cat_name": "Office\/Godown", "sub_categories": [] }, { "cat_id": "20", "cat_name": "House\/Flat", "sub_categories": [] }, { "cat_id": "21", "cat_name": "Car\/Bike", "sub_categories": [] }, { "cat_id": "22", "cat_name": "Events", "sub_categories": [ { "cat_id": "22", "sub_cat_name": "Tent House" } ] }, { "cat_id": "23", "cat_name": "Fancy Dress", "sub_categories": [] }, { "cat_id": "24", "cat_name": "Other", "sub_categories": [ { "cat_id": "24", "sub_cat_name": "Experiences" }, { "cat_id": "24", "sub_cat_name": "Laptop" } ] } ] }  
  </code></pre>
  
  <p>In this i am getting <code>cat_name</code> as Tab name and <code>sub_categories</code> as a Values(List) inside tab.</p>
  
  <p>Here i am receiving value from JSONFormat, After receiving values i am sending those values to Fragment parentclass. which is declare below</p>
  
  <pre><code>public void detail(){
          String  category = null,cat_img,cat_id = null,sub_cat = null,s_name = null;
          JSONObject c = null;
          try {
  
              JSONObject object = new JSONObject(myJSON);
              JSONArray Jarray  = object.getJSONArray("Categories");
  
              for(int i=0;i&lt;Jarray.length();i++){
                   c = Jarray.getJSONObject(i);
  
                  JSONArray moreDetails = c.getJSONArray("sub_categories");
                  category = c.getString("cat_name");
  
                  cat_id = c.getString("cat_id");
                  sub_cat = c.getString("sub_categories");
  
                  fragmentParent.addPage(category,cat_id);
  
  
                  for (int i2 = 0; i2 &lt; moreDetails.length(); i2++) {
  
                     JSONObject detail = moreDetails.getJSONObject(i2);
                     s_name = detail.getString("sub_cat_name");
                      String s_id = detail.getString("cat_id");
                      fragmentParent.addlist(s_name,s_id);
                     Toast.makeText(this, s_name, Toast.LENGTH_SHORT).show();
  
                  }
  
  
  
  
  
              }
  
  
          } catch (JSONException e) {
              e.printStackTrace();
          }
  
  
  
      }
  </code></pre>
  
  <p>FragmentParent.class, After receiving values i am send it to FragmentChild Class.</p>
  
  <pre><code>public class FragmentParent extends Fragment {
      private TabLayout tabLayout;
      private ViewPager viewPager;
      private ViewPagerAdapter adapter;
  
      @Nullable
      @Override
      public View onCreateView(LayoutInflater inflater, ViewGroup container,
          Bundle savedInstanceState) {
          View view = inflater.inflate(R.layout.fragment_parent, container, false);
          getIDs(view);
          setEvents();
          return view;
      }
  
      private void getIDs(View view) {
          viewPager = (ViewPager) view.findViewById(R.id.my_viewpager);
          tabLayout = (TabLayout) view.findViewById(R.id.my_tab_layout);
          adapter = new ViewPagerAdapter(getFragmentManager(), getActivity(), viewPager, tabLayout);
          viewPager.setAdapter(adapter);
      }
  
      int selectedTabPosition;
  
      private void setEvents() {
  
          tabLayout.setOnTabSelectedListener(new TabLayout.ViewPagerOnTabSelectedListener(viewPager) {
              @Override
              public void onTabSelected(TabLayout.Tab tab) {
                  super.onTabSelected(tab);
                  viewPager.setCurrentItem(tab.getPosition());
                  selectedTabPosition = viewPager.getCurrentItem();
                  Log.d("Selected", "Selected " + tab.getPosition());
              }
  
              @Override
              public void onTabUnselected(TabLayout.Tab tab) {
                  super.onTabUnselected(tab);
                  Log.d("Unselected", "Unselected " + tab.getPosition());
              }
          });
      }
  
      public void addPage(String pagename,String id) {
          Bundle bundle = new Bundle();
          bundle.putString("data", pagename);
          bundle.putString("c_id", id);
          FragmentChild fragmentChild = new FragmentChild();
          fragmentChild.setArguments(bundle);
          adapter.addFrag(fragmentChild, pagename);
          adapter.notifyDataSetChanged();
          if (adapter.getCount() &gt; 0) tabLayout.setupWithViewPager(viewPager);
  
          viewPager.setCurrentItem(adapter.getCount() - 1);
          setupTabLayout();
      }
  
      public void addlist(String listname,String id) {
          Bundle bundle = new Bundle();
          bundle.putString("list_name", listname);
          bundle.putString("s_id", id);
  
      }
  
      public void setupTabLayout() {
          selectedTabPosition = viewPager.getCurrentItem();
          for (int i = 0; i &lt; tabLayout.getTabCount(); i++) {
              tabLayout.getTabAt(i).setCustomView(adapter.getTabView(i));
          }
      }
  }
  </code></pre>
  
  <p>And this the FragmentChild Class where i am getting and showing the values inside tabs</p>
  
  <p>FragmentChild.class</p>
  
  <pre><code>public class FragmentChild extends Fragment {
      String childname,img_name,cid,s_list,s_id;
      TextView textViewChildName;
      EditText editText;
  
      @Nullable
      @Override
      public View onCreateView(LayoutInflater inflater, ViewGroup container,
          Bundle savedInstanceState) {
          View view = inflater.inflate(R.layout.fragment_child, container, false);
          Bundle bundle = getArguments();
          childname = bundle.getString("data");
          img_name = bundle.getString("gmi");
          cid = bundle.getString("c_id");
          s_list = bundle.getString("list_name");
          s_id = bundle.getString("s_id");
          getIDs(view);
          return view;
      }
  
      private void getIDs(View view) {
          textViewChildName = (TextView) view.findViewById(R.id.textViewChild);
          textViewChildName.setText(childname+"-"+cid);
  
      }
  
  
  }
  </code></pre>
  
  <p>This is my Output</p>
  
  <p><a href="https://i.stack.imgur.com/AZExs.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/AZExs.png" alt="enter image description here"></a></p>