Home java Android: how to determine the end of the scroll gridview

Android: how to determine the end of the scroll gridview

Author

Date

Category

There is a parser who pulls out the links from the site to the pictures and then with Picasso, they are downloaded to Gridview . Since the pictures are a lot, pull out all the links, and upload pictures, with my implementation, very long

Public Class MainActivity Extends Activity {
  Public ArrayList & LT; String & GT; linklist = New ArrayList & lt; String & GT; ();
  @Override
  PROTECTED VOID OnCreate (Bundle SavedInstanceState) {
    Super.ONCREATE (SavedInstanceState);
    setContentView (R.Layout.Activity_Main);
    Log.d ("Log", "Titlelist:" + linklist);
    New ParsingFile (). execute ();
  }
  Public Class Parsingfile EXTENDS ASYNCTASK & LT; STRING, VOID, STRING & GT; {
    PROTECTED INT PAGES = 0;
    @Override
    PROTECTED VOID ONPREEXECUTE () {
      Log.d ("Log", "Start");
    }
    @Override
    PROTECTED STRING DOINBACKGROUND (STRING ... ARG) {
      Try {
        / * Watch how many pages on the site * /
        Document Doc = jsoup.connect ("http://mintmanga.com/list?sorttype=rate") .get ();
        Elements AllPages = Doc.Select (". Step");
        Element Lastpage = allpages.last ();
        pages = integer.paraseint (lastpage.text ());
      } Catch (IoException E) {
        E.PrintStackTrace ();
      }
      Try {
        / * Collect links on the first page * /
        Document Doc = jsoup.connect ("http://readmanga.me/list?sorttype=rate") .get ();
        Elements link = doc.select ("img [class * = lazy]");
        linklist.clear ();
        For (Element Links: link) {
          linklist.add (Links.attr ("Data-Original"));
        }
      } Catch (IoException E) {
        E.PrintStackTrace ();
      }
      Try {
        / * Running about the rest of the pages and collect links * /
        for (int i = 1; i & lt; pages; i ++) {
          Document Doc = jsoup.connect ("http://readmanga.me/list?sorttype=rate& fffset=" + integer.tostring (I * 70)). Get ();
          Elements link = doc.select ("img [class * = lazy]");
          linklist.clear ();
          For (Element Links: link) {
            linklist.add (Links.attr ("Data-Original"));
          }
        }
      } Catch (IoException E) {
        E.PrintStackTrace ();
      }
      RETURN NULL;
    }
    @Override
    Protected Void Onpostexecute (String Result) {
      / * I send download links * /
      Gridview gridview = (gridview) FindViewByid (R.ID.Images_gridView);
      gridview.setadapter (New Imageadapter (MainActivity.this, LinkList));
      Log.d ("Log", "Pages:" + Pages);
    }
  }
}

Therefore, it would be logical to download not all at once, but as the user flies the tape (for example, on the first page of 20 pictures, they are loaded at once when the user strolts to the end, the pictures from the second picture are loaded, etc. . From here the question: how to determine that the user valves to the end of the filled Gridview ?


Answer 1

You need to process the Onscroll event using onscrollListener .

gridview.setonscrolllistener (new onscrollllistener () {
  @Override
  Public Void Onscroll (AbslistView View, Int FirstVisibleItem, Int VisibleItemCount, Int TotalItemcount) {
    if ((VisibleItemCount + FirstVisibleItem) == TotalItemcount) {
      // User to leafal to the end.
    }
  }
});

is approximately somehow so.

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions