ViewPager + RecyclerView issue in android
<p>Hi I have <code>Tablayout</code> with <code>Viewpager</code> and i am using <code>Fragment</code> for tablayout. Now in every Tablayout fragments I have <code>Recyclerview</code> and displaying items.Please See this my json response </p>

<p><a href="http://pastebin.com/nUswad9s" rel="nofollow">http://pastebin.com/nUswad9s</a></p>

<p>here in "typeMaster": array i have categories "typeName": "Dogs", and i am displaying typenames in tablayout i have 4 tablayout, and inside typemaster i have subcategoreis named "catMaster": and i am trying to display catmaster data in recyclerview,but the issue is in every fragment it shows last data "catName": "Vitamins &amp; Minerals",</p>

<p>Activity</p>

<pre><code>public class CategoriesActivity extends AppCompatActivity{

    private Header myview;
    private ArrayList&lt;SubcategoryModel&gt; subct;
    private ArrayList&lt;CategoryModel&gt; filelist;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.categoris_activity);


        filelist =  (ArrayList&lt;CategoryModel&gt;)getIntent().getSerializableExtra("categorylist");

        System.out.println("Category list size"+filelist.size());
        myview = (Header) findViewById(R.id.categorisactivity_headerView);
        myview.setActivity(this);
        TabLayout tabLayout = (TabLayout) findViewById(R.id.cat_tab_layout);

        for(int i = 0; i &lt; filelist.size(); i++){


             subct=filelist.get(i).getItems();
            for(int j=0;j&lt;subct.size();j++)
            {


            }
            System.out.println("SubCategory list size"+subct.size());
        }


        for(int i = 0; i &lt; filelist.size(); i++){

            tabLayout.addTab(tabLayout.newTab().setText(filelist.get(i).getCategory_typename()));

            ArrayList&lt;SubcategoryModel&gt; subct=filelist.get(i).getItems();
            for(int j=0;j&lt;subct.size();j++)
            {

            }

        }
        Bundle bundleObject = new Bundle();
        bundleObject.putSerializable("key", filelist);
        FirstFragment ff=new FirstFragment();
        ff.setArguments(bundleObject);
        tabLayout.setTabGravity(TabLayout.GRAVITY_FILL);

        final ViewPager viewPager = (ViewPager) findViewById(R.id.categories_pager);


        CategoriesAdapter  mPagerAdapter = new CategoriesAdapter(getSupportFragmentManager(),tabLayout.getTabCount());
        viewPager.setAdapter(mPagerAdapter);
        viewPager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(tabLayout));
        tabLayout.setOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
            @Override
            public void onTabSelected(TabLayout.Tab tab) {
                viewPager.setCurrentItem(tab.getPosition());

            }

            @Override
            public void onTabUnselected(TabLayout.Tab tab) {

            }

            @Override
            public void onTabReselected(TabLayout.Tab tab) {

            }
        });

    }



   public class CategoriesAdapter extends FragmentStatePagerAdapter {
        ArrayList&lt;CategoryModel&gt; catlist;
       int numoftabs;

        public CategoriesAdapter(FragmentManager fm, int numoftabs) {
            super(fm);
            this.numoftabs = numoftabs;
        }

        @Override
        public Fragment getItem(int position) {

            Log.v("adapter", "getitem" + String.valueOf(position)+subct.size());
            return FirstFragment.create(position,subct);
        }

        @Override
        public int getCount() {
            return numoftabs;
        }
    }



}
</code></pre>

<p>Fragment</p>

<pre><code>public class FirstFragment extends Fragment {
    // Store instance variables
    public static final String ARG_PAGE = "page";
    private int mPageNumber;
    private Context mContext;
    private int Cimage;
    private ArrayList&lt;SubcategoryModel&gt; subcatlist;
    private RecyclerView rcylervw;
    private  ArrayList&lt;CategoryModel&gt; filelist;
     ArrayList&lt;SubcategoryModel&gt; subct;


    public static FirstFragment create(int pageNumber,ArrayList&lt;SubcategoryModel&gt; subct){
        FirstFragment fragment = new FirstFragment();
        Bundle args = new Bundle();
        args.putInt(ARG_PAGE, pageNumber);
        args.putSerializable("key", subct);
        fragment.setArguments(args);
        return fragment;
    }


    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mPageNumber = getArguments().getInt(ARG_PAGE);


        subct= (ArrayList&lt;SubcategoryModel&gt;) getArguments().getSerializable("key");
        System.out.println("Frag Category list size"+subct.size());

      /*  for(int i = 0; i &lt; filelist.size(); i++){
            subct=filelist.get(i).getItems();
            for(int j=0;j&lt;subct.size();j++)
            {

            }
            System.out.println("Frag SubCategory list size"+subct.size());
        }*/
        // image uri get uri of image that saved in directory of app
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {

        ViewGroup rootView = (ViewGroup) inflater
                .inflate(R.layout.test, container, false);


        rcylervw=(RecyclerView)rootView.findViewById(R.id.subcategory_recycler_view);
        rcylervw.setHasFixedSize(true);
        MyAdapter adapter = new MyAdapter(subct);
        rcylervw.setAdapter(adapter);

        LinearLayoutManager llm = new LinearLayoutManager(getActivity());
        rcylervw.setLayoutManager(llm);

        return rootView;
    }


// this method is not very important


}
</code></pre>

<p>MyAdapter</p>

<pre><code>public class MyAdapter extends RecyclerView.Adapter&lt;MyAdapter.MyViewHolder&gt; {
    private ArrayList&lt;SubcategoryModel&gt; mDataset;



    public static class MyViewHolder extends RecyclerView.ViewHolder {

        public TextView mTextView;
        public MyViewHolder(View v) {
            super(v);
            mTextView = (TextView) v.findViewById(R.id.subcategory_text);
        }
    }

    // Provide a suitable constructor (depends on the kind of dataset)
    public MyAdapter(ArrayList&lt;SubcategoryModel&gt; myDataset) {
        mDataset = myDataset;
    }

    // Create new views (invoked by the layout manager)
    @Override
    public MyAdapter.MyViewHolder onCreateViewHolder(ViewGroup parent,
                                                     int viewType) {
        // create a new view
        View v = LayoutInflater.from(parent.getContext())
                .inflate(R.layout.list_item_subcategory, parent, false);
        // set the view's size, margins, paddings and layout parameters
        MyViewHolder vh = new MyViewHolder(v);
        return vh;
    }

    @Override
    public void onBindViewHolder(MyViewHolder holder, int position) {
        holder.mTextView.setText(mDataset.get(position).getSubCategory_name());
    }

    @Override
    public int getItemCount() {
        return mDataset.size();
    }
}
</code></pre>

<p>Output i am getting right now  </p>

<p><a href="https://i.stack.imgur.com/tBNrS.png" rel="nofollow"><img src="https://i.stack.imgur.com/tBNrS.png" alt="enter image description here"></a></p>

<p><a href="https://i.stack.imgur.com/m0i6H.png" rel="nofollow"><img src="https://i.stack.imgur.com/m0i6H.png" alt="enter image description here"></a></p>

<p><a href="https://i.stack.imgur.com/eCJor.png" rel="nofollow"><img src="https://i.stack.imgur.com/eCJor.png" alt="enter image description here"></a></p>

<p>As you can see it shows same result "Vitamin &amp; Minerals" in every tabs..i want different subcategories instead of same.</p>