Until that time, all data was loaded simply when a person opens the application in asynkTask. And now it was necessary to use the cache and LazyLoad, but I cannot understand how to use it correctly. It was necessary that, for example, as in VK, I pulled the list to the bottom and the data began to be updated -> if there is new data, then load it, no means no.

Here is the structure of my project now:

//сюда загружается json ArrayList<NewsObject> newsList; ListView list; protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); //код list = (ListView) findViewById(R.id.list); newsList = new ArrayList<NewsObject>(); //код //загрузка новостей(новости все в json) new NewsAsynkTask().execute(); } public class NewsAsynkTask extends AsyncTask<String , Void, String> { //код protected String doInBackground(String... params) { //тут я добавляю json в обьект //потом добавляю в список, обьекты newsList.add(newsObject); } protected void onPostExecute(String file_url) { //включается адаптер NewsAdapter adapter = new NewsAdapter(getApplicationContext(), R.layout.n_news_list_object, newsList); list.setAdapter(adapter); } } 

What is the algorithm of action? Here is how I imagine it:

  1. The application opens, if there is an Internet then we read for example 10 posts of the last posts.

  2. If the user pulled the list down, updating the data, the new records are output.

  3. If the user has reached the end of the list, load another 10 posts.

1 answer 1

Download if at the end of the list! When you first start will load the first portion.

  listView.setOnScrollListener(new AbsListView.OnScrollListener() { @Override public void onScrollStateChanged(AbsListView view, int scrollState) { } @Override public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) { if (!isLoading && (totalItemCount - visibleItemCount) <= firstVisibleItem) { isLoading = true; //После загрузки, опустить флаг load(); //Загрузка footerView.setVisibility(View.VISIBLE); //Отображение футера, прогресбар какой-нибудь внизу, после загрузки убрать. } } });