I have a ViewPager which swipes between Fragments. I\'m using a FragmentStatePagerAdapter to feed the Fragments to the ViewPager. If the user swipes left at a normal pace, and t
I just realized that you're doing a lot of UI work in onCreate
() in the main Activity. It is more proper to do the work in onCreateView
(). I believe the Android framework is not finish doing the UI work in onCreate
() and therefore you see incomplete UI rendering.
I know this is not clearly stated in Android documentation. If you check other SO posts or sample projects, other developers do little UI work in onCreate
(). At least, the layouts are simpler than yours.
Here is my suggestion.
Inflate the fragtest
layout in an Activity or Fragment in method onCreateView
(), using the ID listed on post. Notice the override method only inflates.
Sample code:
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
return inflater.inflate(R.layout.fragtest, container, false);
}
On a Fragment, start accessing the UI elements and the ViewPager, using the ID listed on post. Sample code:
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
mProfilesViewPager = (ViewPager) findViewById(R.id.viewPager);
...