ViewPager, same Fragment with RecyclerView for multiple tabs
<p>I am working on a app, which having a category list.
If we click on category then I have to show different subcategories in tabs, each tab having a list of products.</p>

<p>Everything is working fine tabs and fragment are loaded with correct data, only <strong>recyclerview</strong> <strong>onClick</strong> gives <strong>incorrect item</strong>(items from adjacent fragment's recyclerview). Mostly happens on viewpager swipe.</p>

<p><strong>code in Activity:</strong></p>

<pre><code>    PagerAdapter adapter = new PagerAdapter
            (getSupportFragmentManager(), tabLayout.getTabCount(), response); 
    // response is a list of subcategories and products 
    viewPager.setOffscreenPageLimit(1);
    viewPager.setAdapter(adapter);
    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) {

        }
    });
</code></pre>

<p><strong>code in PagerAdapter:</strong></p>

<pre><code>public class PagerAdapter extends FragmentStatePagerAdapter {
int mNumOfTabs;
SubCategoryResponse response;

public PagerAdapter(FragmentManager fm, int NumOfTabs, SubCategoryResponse response) {
    super(fm);
    this.mNumOfTabs = NumOfTabs;
    this.response = response;
}

@Override
public Fragment getItem(int position) {
    L.m(position +" =&gt; "+response.getList().get(position).getProducts().get(0).getName());
    TabFragment fragmentDummy = TabFragment.getInstance(position, response.getList().get(position).getProducts());
    return fragmentDummy;
}

@Override
public int getCount() {
    return mNumOfTabs;
}
</code></pre>

<p>}</p>

<p><strong>code in TabFragment:</strong></p>

<pre><code>public class TabFragment extends Fragment implements ProductAdapter.mClickListener {
@Bind(R.id.list_container_fragment)
LinearLayout listContainerFragment;
@Bind(R.id.list_products)
RecyclerView productListView;

private ProductAdapter productsAdapter;
private Dialog myDialog;
private LinearLayoutManager linearLayoutManager;
private ArrayList&lt;Products&gt; responseProducts = null;

public TabFragment() {
    // Required empty public constructor
}

public static TabFragment getInstance(int position, ArrayList&lt;Products&gt; response) {
    TabFragment fragmentDummy = new TabFragment();
    Bundle args = new Bundle();
    args.putParcelableArrayList("PRODUCTS", response);
    args.putInt("position", position);
    fragmentDummy.setArguments(args);
    return fragmentDummy;
}

@Override
public void setArguments(Bundle args) {
    super.setArguments(args);
    this.responseProducts = args.getParcelableArrayList("PRODUCTS");
}

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    // Inflate the layout for this fragment
    View view = inflater.inflate(R.layout.fragment_tab, container, false);
    ButterKnife.bind(this, view);
    linearLayoutManager = new LinearLayoutManager(getActivity());
    linearLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
    productListView.setLayoutManager(linearLayoutManager);
    productListView.setItemAnimator(new DefaultItemAnimator());
    populateList();
    return view;
}

public void populateList() {
    L.m("populate list");
    if (responseProducts.size() &gt; 0) {
        L.m("Inside populate list =&gt; " + responseProducts.get(0).getName());
        productsAdapter = new ProductAdapter(responseProducts);
        productsAdapter.setListner(getActivity(), this);
        productListView.setAdapter(productsAdapter);
        productListView.setHasFixedSize(true);
    } else {
        showError("No Products to Show");
    }
}

public void showError(String msg) {
    SnackbarManager.show(
            Snackbar.with(getActivity()) // context
                    .text(msg) // text to be displayed
                    .textColor(Color.WHITE) // change the text color
                            // .textTypeface(myTypeface) // change the text font
                    .color(getResources().getColor(R.color.colorPrimary)) // change the background color
                    .duration(Snackbar.SnackbarDuration.LENGTH_LONG)
            , getActivity());
}

@Override
public void mClickDetails(View view, int pos) {
    startActivity(new Intent(getActivity(), ProductDetailsActivity.class)
            .putExtra("PRODUCT", responseProducts.get(pos).getName()));
}

@Override
public void onResume() {
    // TODO Auto-generated method stub
    super.onResume();
    //populateList();
}
}
</code></pre>

<p>I don't know whats going wrong here.</p>

<p>Please help, Thank You.</p>