0

im having some issues with screen onrientations changes.. i have my MainActivity with a tablayout and recycle view. Works all perfectly when i run my app, but when i turn my device to landscape, my methods dont get called, i have an ViewPagerAdapter, the method getItem dont get called when the screen changes..

MainActivity:

 viewPager = (ViewPager) findViewById(R.id.viewpager);
 viewPagerAdapter = new ViewPagerAdapter(getSupportFragmentManager(), this);
 viewPager.setAdapter(viewPagerAdapter);

the contructor, and the getCount method enters normal, but getItem doesnt. im doing something wrong or forgeting something ?

i need that my method getItem(..) from ViewPagerAdapter gets called..

Thank you!

2 Answers2

0

Are you using onRestoreInstanceState() take a look at the documentation on handling configuration changes. https://developer.android.com/guide/topics/resources/runtime-changes.html

Isaac Osiemo
  • 116
  • 1
  • 9
0

Your fragments are kept alive during the orientation change, and hence they don't need to be recreated afterwards. If they don't need to be recreated, getItem() won't be called.

See this answer to the question "When is FragmentPagerAdapter's getItem called?".

Community
  • 1
  • 1
Magnus
  • 17,157
  • 19
  • 104
  • 189