I tried this, but wrong lists get binded to the recyclerview. I tried SparseArray as well, even that doesn't work. getItem() gets called twice when i start Mainactivity. How do I handle the position returned? I tried returning viewpager currentItem, even that doesn't work.
MainActivity
public class PagerAdapter extends FragmentStatePagerAdapter {
int mNumOfTabs;
public PagerAdapter(android.support.v4.app.FragmentManager fragmentManager, int tabCount)
{
super(fragmentManager);
this.mNumOfTabs = tabCount;
}
@Override
public Fragment getItem(int position) {
return Categories_Fragment.newInstance(position);
}
@Override
public int getCount() {
return mNumOfTabs;
}
}
Categories_Fragment
public class Categories_Fragment extends Fragment
{
private RecyclerView lvMessages;
private int fromPage;
public static Categories_Fragment newInstance(int num) {
Categories_Fragment f = new Categories_Fragment();
// Supply num input as an argument.
Bundle args = new Bundle();
args.putInt("from", num);
f.setArguments(args);
return f;
}
@Override
public void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
fromPage = getArguments().getInt("from");
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// TODO Auto-generated method stub
View rootView = inflater.inflate(R.layout.categories_filter, container, false);
lvMessages = (RecyclerView)rootView.findViewById(R.id.lv_categories_filter);
LinearLayoutManager x = new LinearLayoutManager(getActivity());
x.setOrientation(LinearLayoutManager.VERTICAL);
lvMessages.setLayoutManager(x);
return rootView;
}
@Override
public void onActivityCreated(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onActivityCreated(savedInstanceState);
// bind different data to the RecyclerView based on fromPage value.
}
}
public static class Categories_Fragment extends Fragment
– Boltzmann