I am using a viewpager to swipe between Fragments. However, the fragments blink/flash whenver I am loading the first fragment or any newly loaded fragment. any ideas ? I tried the HardwareAcceleration disable but nothing.
Related
I have a single activity that uses a bunch of different Fragments. I have a TabContainer Fragment that holds a TabLayout which uses a ViewPager to handle tab navigation. Each Tab is its own Fragment.
In one of my tabs, I want to tap and place a fragment on top of my Tabbed fragment. This is meant to be a "details" sort of screen, so I don't want the tabs to be visible. I'm using this and it works as intended:
fragmentTransaction.replace(android.R.id.content, fragmentToDisplay).addToBackStack(null).commit();
Now, when I navigate back, the content in my tab is empty. The content in the tab directly next to that tab is also empty. When I navigate two tabs away, the content is recreated and the normal functionality returns. Why is content not being recreated on the tabs initially when I remove my "detail" fragment?
It turns out that I was simply not passing the correct FragmentManager to the FragmentStatePagerAdapter.
I needed to call getChildFragmentManager() on the Fragment, not getSupportFragmentManager() on the activity.
Thanks to these two posts for the answer:
Fragment in ViewPager not restored after popBackStack
and: Replacing ViewPager with Fragment - Then Navigating Back
I have the next scenario
An activity with a FrameLayout. In the FrameLayout I load fragments using replace
android.support.v4.app.Fragment contentToLoad = null;
android.support.v4.app.FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
...get the proper fragment depending of some logic
contentToLoad = new FragmentDemoContent();
fragmentTransaction.replace(R.id.fl_contentcontainer, contentToLoad);
fragmentTransaction.addToBackStack(null);
fragmentTransaction.commit();
One of the fragments contains a ViewPager and a SlidingTabLayout (Copied from https://github.com/codepath/android_guides/wiki/Google-Play-Style-Tabs-using-SlidingTabLayout)
Inside the ViewPager I'm loading as pages other fragments, each fragment is a WebView that load a local content from assets. The adapter extends FragmentPagerAdapter
When I first load this fragment everything works fine, and I can swipe and load all the pages. But If I load other fragment and I came back to load the fragment with the ViewPager again, I get random blank pages, sometimes is the first one, sometime others. Sometimes also when I swipe back the previous blank page appears, but not always
I have tried, with no luck:
Check if its a WebView problem. It is not, using instead of the
fragments with the webviews blank default fragments with simply a
textview, I get the random blank pages too.
Invalidate the views, the pager... after each scroll or page changed
This approach ViewPager PagerAdapter not updating the View
Set http://developer.android.com/reference/android/support/v4/view/ViewPager.html#setOffscreenPageLimit%28int%29
to load all the pages
Any ideas or something that we can try?
I figured out the problem. At the child fragment we were using getSupportFragmentManager instead of getChildFragmentManager. After replacing it it works ok.
Webview has rendering issue it takes time to load you can use textView with
myTextView.setText(Html.fromHtml("your html text"));
So in my android application, I am currently using viewpager as well as fragments. What I am trying to do is start off the application using a viewpager, which is a fragment itself, that contains three fragments. The third fragment in the viewpager has a button, when clicked on will replace the viewpager fragment with another fragment. I press the button, and the viewpager fragment is replaced with the other fragment ok. But when I press the back button, it returns to the viewpager fragment, but all I see it a blank screen. What should happen is that I should see the third fragment in the viewpager. I think what is happening is that when I press the back button, it goes back to the viewpager, but does not load the fragments in the viewpager. Does anyone know why this is happening?
once again, I am following this tutorial: androidhive - tab layout with swipe able views . All 3 fragment tabs are loaded with different information and logic and layouts. I would like to refresh each fragment when their tabs have been clicked as it auto loads the fragments from start as it uses the view pager. Is there any simplest way out that I could load only a/1 fragment using view pager? Or to reload the fragments? Thanks for your help!
Try to add this to your viewpager:
MY_VIEWPAGER.setOffscreenPageLimit(0);
Check out the documentation.
Pages beyond this limit will be recreated from the adapter when needed.
The limit of 0 will cause a recreation of the fragment when you open a tab.
I have a custom ViewPager in which I have 4 fragments, each fragment has different listviews, and its on the start screen of the application. The listview's are taking time to load as soon as the application starts. I'm not pulling any data into the listview, its just the implementation. Implemented OnPageChangeListener to change the listview as I swipe through the fragments
Why does this happen?
changed the implementation, instead of fragments I used PagerAdapter.