I have list of objects Offer and with their data I try filling the fragments (one object per fragment). It works in the way that it shows them but the first one that is shown is really the second and after I swipe two times to the left and come back to the first then it is there (the first one)
I know that this question relates to this one
ViewPager first fragment shown is always wrong with FragmentStatePager
But the question is self answerd and not well understandable so I really need help
This is me code: Inside Fragment activity
public class OffersDisplay extends FragmentActivity {
/*some inicializations for layout and stuff*/
listOfOffers = (ArrayList<Offer>) getIntent().getSerializableExtra("listOfOffers");
...
public static class MyAdapter extends FragmentStatePagerAdapter {
public MyAdapter(FragmentManager fragmentManager) {
super(fragmentManager);
}
@Override
public int getCount() {
return ITEMS;
}
@Override
public Fragment getItem(int position) {
return ImageFragment.init(listOfOffers.get(position));
}
}
}
And my ImageFragment class is seperate and looks like this
public class ImageFragment extends Fragment {
//some inits again
public static ImageFragment init(Offer offer) {
// Supply val input as an argument.
name = offer.getName();
description = offer.getDescription();
moreInfoURL = offer.getMoreInfoURL();
return new ImageFragment();
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
layoutView = inflater.inflate(R.layout.fragment_image, container,
false);
tv = layoutView.findViewById(R.id.text);
((TextView) tv).setText(name + "\n"+ description);
iview = layoutView.findViewById(R.id.image);
//...some inits
((ImageView) iview).setImageBitmap(pic);
return layoutView ;
}
}