Java – how to load fragments in viewpager to select
•
Java
Im uses three segments in viewpager. The problem of loading big data in large data loader works well in devices like HTC, but it takes a lot of time in low-end devices This is mainly because when I implement pageadapter, I put fragments in an ArrayList, which forces fragments to load when the main body is active I need it just to "load" the first clip (main) and the user "swype" to load other clips Is there any way to achieve it? This is my pageadapater
public class PagerAdapter extends FragmentPagerAdapter { private final ArrayList<Fragment> mFragments = new ArrayList<Fragment>(); // private final ArrayList<String> titulos = new ArrayList<String>(); // private int NUM_PAGES =0; public PagerAdapter(FragmentManager manager,int num_pages) { super(manager); // this.NUM_PAGES = num_pages; } public void addFragment(Fragment fragment,String title) { mFragments.add(fragment); notifyDataSetChanged(); } @Override public int getCount() { //return NUM_PAGES; return mFragments.size(); } @Override public Fragment getItem(int position) { return mFragments.get(position); } }
Solution
Sun's above method doesn't work for me (maybe for you), but I think I'll share my editing method too Great, good way!
private boolean _hasLoadedOnce= false; // your boolean field @Override public void setUserVisibleHint(boolean isFragmentVisible_) { super.setUserVisibleHint(true); if (this.isVisible()) { // we check that the fragment is becoming visible if (isFragmentVisible_ && !_hasLoadedOnce) { new NetCheck().execute(); _hasLoadedOnce = true; } } }
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码