Fragment Implementing Lazy Loading

Source: Internet
Author: User

  1. Import android.support.v4.app.Fragment;
  2. Public abstract class Basefragment extends Fragment {
  3. /** Fragment Current status is visible * /
  4. protected Boolean isVisible;
  5. //setuservisiblehint Adapter Each fragment switch will be called, if the switch to the current page, then isvisibletouser==true, otherwise false
  6. @Override
  7. public void Setuservisiblehint (boolean isvisibletouser) {
  8. Super.setuservisiblehint (Isvisibletouser);
  9. if (isvisibletouser) {
  10. IsVisible = true;
  11. Onvisible ();
  12. } Else {
  13. IsVisible = false;
  14. Oninvisible ();
  15. }
  16. }
  17. /** 
  18. * Visible
  19. */
  20. protected void Onvisible () {
  21. Lazyload ();
  22. }
  23. /** 
  24. * Not visible
  25. */
  26. protected void Oninvisible () {
  27. }
  28. /** 
  29. * Lazy Loading
  30. * Subclasses must override this method
  31. */
  32. protected abstract void Lazyload ();
  33. }

Gca

  1. Public View Oncreateview (layoutinflater inflater, ViewGroup container, Bundle savedinstancestate) {
  2. View view = Inflater.inflate (R.layout.fragment, container, false);
  3. ContentText = (TextView) View.findviewbyid (r.id.content);
  4. ProgressBar = (ProgressBar) View.findviewbyid (R.id.progressbar);
  5. isprepared = true;
  6. Lazyload ();
  7. return view;
  8. }
  9. @Override
  10. protected void Lazyload () {
  11. if (!isprepared | |!isvisible | | mhasloadedonce) {
  12. return;
  13. }
  14. new Asynctask<void, Void, boolean> () {

Fragment Implementing Lazy Loading

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.