Parsing news from a single news portal, which are subsequently displayed in my RecyclerView . I do not include promotional news on my list, so it happens that I get from 24 to 27 articles from the portal page. I want to make, as soon as an element with the position list.size()-2 on the screen, the application starts parsing the next page, adding it to RecyclerView , etc.

Maybe someone has a ready piece of code on my question? I would be very grateful!

  • Not exactly the answer, but you may be interested in the option "how to organize the logic of downloading data from the network and placing them in RecyclerView " presented recently in one report . The code itself is here . - Alex Kisel

3 answers 3

the recycler has OnScrollListener. Actually you need to write your own implementation. How to do this - it is better to read descriptions of methods for obtaining the number of list items in the recycler documentation.

Googling found this example on github

    In general, thanks guys! I collected information from sources, implemented a simple scroll processing in this way:

     recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() { @Override public void onScrolled(RecyclerView recyclerView, int dx, int dy) { super.onScrolled(recyclerView, dx, dy); if(dy>0){ LinearLayoutManager layoutManager = (LinearLayoutManager) newsList.getLayoutManager(); int lastVisibleItemPosition = layoutManager.findLastVisibleItemPosition(); Log.d("logs", "lastVisibleItemPosition-"+lastVisibleItemPosition); if (lastVisibleItemPosition > list.size()-2){ // ArrayList<NewsModel> list; numberPage++; //номер страницы откуда нужно парсить, перваоначальное значение было 1. parseAndSaveNews(numberPage); //парсинг и сохранение новостей со следующей страницы } } } }); 

      If I understand you, you need endless scrolling for RecyclerView . For such purposes, you can use EndlessScrollListener (or use it as a basis). Examples and details can be found here .