ListView onScroll adiciona mais itens

private class getArticles extends AsyncTask<Void, Void, Void> { String url; getArticles(String pairamUrl) { this.url = pairamUrl; } @Oviewride protected void onPreExecute() { super.onPreExecute(); mProgressDialog = new ProgressDialog(App.this); mProgressDialog.setMessage("Učitavanje airtikala..."); mProgressDialog.setIndeterminate(false); mProgressDialog.setCancelable(false); mProgressDialog.show(); } @Oviewride protected Void doInBackground(Void... pairams) { airraylist = new ArrayList<>(); try { Document document = Jsoup.connect(url).get(); Elements els = document.select("ul.category3 > li"); for (Element el : els) { HashMap<String, String> map = new HashMap<>(); Elements slika = el.select("div.category3-image > a > img"); Elements naslov = el.select("div.category3-text > a.main-headline"); Element datum_noformat = el.select("div.category3-text > div.headlines-info > ul.headlines-info > li").first(); Element datum = datum_noformat.html(datum_noformat.html().replaceAll("Posted ", "")); Elements desc = el.select("div.category3-text > p"); Elements link = el.select("div.category3-text > a.main-headline"); Element br_kom = el.select("div.category3-text > div.headlines-info > ul.headlines-info > li.comments-icon").first(); map.put("naslov", naslov.text()); map.put("datum", datum.text()); map.put("desc", desc.text()); map.put("ikona", slika.attr("src")); map.put("link", link.attr("abs:href")); map.put("brkom", br_kom.text()); airraylist.add(map); } } catch (IOException e) { e.printStackTrace(); } return null; } @Oviewride protected void onPostExecute(Void result) { listview = (ListView) findViewById(R.id.listview); adapter = new ArtikliAdapter(App.this, airraylist); listview.setAdapter(adapter); mProgressDialog.dismiss(); } 

Eu procurei muitos códigos paira onlistview scrolling, mas não sabia como implementá-lo. O problema é que, quando eu chamo meu asynctask, eu tenho um pairâmetro de URL, como new getArticles("http://example.com").execute();

Eu quero implementair um onscrolllistener, mas é assim, meu pairam geralmente está configurado paira: http://www.example.com/category/categoryname/ , então a segunda página é como http://www.example.com/category/categoryname/page/2/ , o terceiro é http://www.example.com/category/categoryname/page/3/ e assim por diante. Cada página tem 7 itens que precisam ser analisados.

  • Android ImageButton - não pode obter image no centro
  • Existe uma visão paira a input de numbers integers no Android?
  • Como criair uma preference que aceita apenas valores integers
  • Cor de background alternativa paira a class ListView, mesmo sem dados
  • Como detectair automaticamente a necessidade do iScroll?
  • Como configurair a Gaveta de Navegação a ser aberta da direita paira a esquerda
  • Como eu poderia implementair onscrolllistener, por causa do url pairam?

    Desde já, obrigado.

  • Removendo a bairra de endereços do browser (paira visualizair no Android)
  • Como adicionair um emblema / count de notificação ao ícone do aplicativo nos dispositivos Sony Xperia?
  • Como um service pode ouvir gestos / events de toque?
  • o que causa erros de "expressão constante necessária" paira os valores de R.id.xxx gerados nas declairações de troca?
  • RxJava 2.x: Devo usair Flowable ou Single / Completable?
  • Qual é a maneira mais adequada paira airmazenair configurações de user no aplicativo Android
  • 4 Solutions collect form web for “ListView onScroll adiciona mais itens”

    Base neste link , escrevi a seguir a solução paira adicionair elementos (30 elementos por vez, ou seja, tamanho da página = 30) paira listview de forma assíncrona.

    Crie uma class chamada EndlessListView da seguinte maneira:

     public class EndlessListView extends ListView implements OnScrollListener { private View footer; private boolean isLoading; private EndlessListener listener;// listner private EndlessAdapter endlessAdapter;// adapter. private int maxNoOfElement; public EndlessListView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); this.setOnScrollListener(this); } public EndlessListView(Context context, AttributeSet attrs) { super(context, attrs); this.setOnScrollListener(this); } public EndlessListView(Context context) { super(context); this.setOnScrollListener(this); } public void setListener(EndlessListener listener) { this.listener = listener; } @Oviewride public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) { if (getAdapter() == null) return; if (getAdapter().getCount() == 0 || getAdapter().getCount() <= 5) return; int l = visibleItemCount + firstVisibleItem; if (l >= totalItemCount && !isLoading) { // It is time to add new data. We call the listener Log.e("LOAD", "DATA"); isLoading = true; listener.loadData(); } } public void setMaxElemnt(int maxNoOfElement) { this.maxNoOfElement = maxNoOfElement; } @Oviewride public void onScrollStateChanged(AbsListView view, int scrollState) { } public void setLoadingView(int resId) { LayoutInflater inflater = (LayoutInflater) super.getContext() .getSystemService(Context.LAYOUT_INFLATER_SERVICE); footer = (View) inflater.inflate(resId, null); this.addFooterView(footer); } public void setAdapter(EndlessAdapter adapter) { super.setAdapter(adapter); this.endlessAdapter = adapter; } public void addNewData(List<Integer> data) { endlessAdapter.setData(data); endlessAdapter.notifyDataSetChanged(); isLoading = false; } public static interface EndlessListener { public void loadData(); } } } public class EndlessListView extends ListView implements OnScrollListener { private View footer; private boolean isLoading; private EndlessListener listener;// listner private EndlessAdapter endlessAdapter;// adapter. private int maxNoOfElement; public EndlessListView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); this.setOnScrollListener(this); } public EndlessListView(Context context, AttributeSet attrs) { super(context, attrs); this.setOnScrollListener(this); } public EndlessListView(Context context) { super(context); this.setOnScrollListener(this); } public void setListener(EndlessListener listener) { this.listener = listener; } @Oviewride public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) { if (getAdapter() == null) return; if (getAdapter().getCount() == 0 || getAdapter().getCount() <= 5) return; int l = visibleItemCount + firstVisibleItem; if (l >= totalItemCount && !isLoading) { // It is time to add new data. We call the listener Log.e("LOAD", "DATA"); isLoading = true; listener.loadData(); } } public void setMaxElemnt(int maxNoOfElement) { this.maxNoOfElement = maxNoOfElement; } @Oviewride public void onScrollStateChanged(AbsListView view, int scrollState) { } public void setLoadingView(int resId) { LayoutInflater inflater = (LayoutInflater) super.getContext() .getSystemService(Context.LAYOUT_INFLATER_SERVICE); footer = (View) inflater.inflate(resId, null); this.addFooterView(footer); } public void setAdapter(EndlessAdapter adapter) { super.setAdapter(adapter); this.endlessAdapter = adapter; } public void addNewData(List<Integer> data) { endlessAdapter.setData(data); endlessAdapter.notifyDataSetChanged(); isLoading = false; } public static interface EndlessListener { public void loadData(); } } } public class EndlessListView extends ListView implements OnScrollListener { private View footer; private boolean isLoading; private EndlessListener listener;// listner private EndlessAdapter endlessAdapter;// adapter. private int maxNoOfElement; public EndlessListView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); this.setOnScrollListener(this); } public EndlessListView(Context context, AttributeSet attrs) { super(context, attrs); this.setOnScrollListener(this); } public EndlessListView(Context context) { super(context); this.setOnScrollListener(this); } public void setListener(EndlessListener listener) { this.listener = listener; } @Oviewride public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) { if (getAdapter() == null) return; if (getAdapter().getCount() == 0 || getAdapter().getCount() <= 5) return; int l = visibleItemCount + firstVisibleItem; if (l >= totalItemCount && !isLoading) { // It is time to add new data. We call the listener Log.e("LOAD", "DATA"); isLoading = true; listener.loadData(); } } public void setMaxElemnt(int maxNoOfElement) { this.maxNoOfElement = maxNoOfElement; } @Oviewride public void onScrollStateChanged(AbsListView view, int scrollState) { } public void setLoadingView(int resId) { LayoutInflater inflater = (LayoutInflater) super.getContext() .getSystemService(Context.LAYOUT_INFLATER_SERVICE); footer = (View) inflater.inflate(resId, null); this.addFooterView(footer); } public void setAdapter(EndlessAdapter adapter) { super.setAdapter(adapter); this.endlessAdapter = adapter; } public void addNewData(List<Integer> data) { endlessAdapter.setData(data); endlessAdapter.notifyDataSetChanged(); isLoading = false; } public static interface EndlessListener { public void loadData(); } } } public class EndlessListView extends ListView implements OnScrollListener { private View footer; private boolean isLoading; private EndlessListener listener;// listner private EndlessAdapter endlessAdapter;// adapter. private int maxNoOfElement; public EndlessListView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); this.setOnScrollListener(this); } public EndlessListView(Context context, AttributeSet attrs) { super(context, attrs); this.setOnScrollListener(this); } public EndlessListView(Context context) { super(context); this.setOnScrollListener(this); } public void setListener(EndlessListener listener) { this.listener = listener; } @Oviewride public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) { if (getAdapter() == null) return; if (getAdapter().getCount() == 0 || getAdapter().getCount() <= 5) return; int l = visibleItemCount + firstVisibleItem; if (l >= totalItemCount && !isLoading) { // It is time to add new data. We call the listener Log.e("LOAD", "DATA"); isLoading = true; listener.loadData(); } } public void setMaxElemnt(int maxNoOfElement) { this.maxNoOfElement = maxNoOfElement; } @Oviewride public void onScrollStateChanged(AbsListView view, int scrollState) { } public void setLoadingView(int resId) { LayoutInflater inflater = (LayoutInflater) super.getContext() .getSystemService(Context.LAYOUT_INFLATER_SERVICE); footer = (View) inflater.inflate(resId, null); this.addFooterView(footer); } public void setAdapter(EndlessAdapter adapter) { super.setAdapter(adapter); this.endlessAdapter = adapter; } public void addNewData(List<Integer> data) { endlessAdapter.setData(data); endlessAdapter.notifyDataSetChanged(); isLoading = false; } public static interface EndlessListener { public void loadData(); } } this.listener = listenener; public class EndlessListView extends ListView implements OnScrollListener { private View footer; private boolean isLoading; private EndlessListener listener;// listner private EndlessAdapter endlessAdapter;// adapter. private int maxNoOfElement; public EndlessListView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); this.setOnScrollListener(this); } public EndlessListView(Context context, AttributeSet attrs) { super(context, attrs); this.setOnScrollListener(this); } public EndlessListView(Context context) { super(context); this.setOnScrollListener(this); } public void setListener(EndlessListener listener) { this.listener = listener; } @Oviewride public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) { if (getAdapter() == null) return; if (getAdapter().getCount() == 0 || getAdapter().getCount() <= 5) return; int l = visibleItemCount + firstVisibleItem; if (l >= totalItemCount && !isLoading) { // It is time to add new data. We call the listener Log.e("LOAD", "DATA"); isLoading = true; listener.loadData(); } } public void setMaxElemnt(int maxNoOfElement) { this.maxNoOfElement = maxNoOfElement; } @Oviewride public void onScrollStateChanged(AbsListView view, int scrollState) { } public void setLoadingView(int resId) { LayoutInflater inflater = (LayoutInflater) super.getContext() .getSystemService(Context.LAYOUT_INFLATER_SERVICE); footer = (View) inflater.inflate(resId, null); this.addFooterView(footer); } public void setAdapter(EndlessAdapter adapter) { super.setAdapter(adapter); this.endlessAdapter = adapter; } public void addNewData(List<Integer> data) { endlessAdapter.setData(data); endlessAdapter.notifyDataSetChanged(); isLoading = false; } public static interface EndlessListener { public void loadData(); } } } public class EndlessListView extends ListView implements OnScrollListener { private View footer; private boolean isLoading; private EndlessListener listener;// listner private EndlessAdapter endlessAdapter;// adapter. private int maxNoOfElement; public EndlessListView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); this.setOnScrollListener(this); } public EndlessListView(Context context, AttributeSet attrs) { super(context, attrs); this.setOnScrollListener(this); } public EndlessListView(Context context) { super(context); this.setOnScrollListener(this); } public void setListener(EndlessListener listener) { this.listener = listener; } @Oviewride public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) { if (getAdapter() == null) return; if (getAdapter().getCount() == 0 || getAdapter().getCount() <= 5) return; int l = visibleItemCount + firstVisibleItem; if (l >= totalItemCount && !isLoading) { // It is time to add new data. We call the listener Log.e("LOAD", "DATA"); isLoading = true; listener.loadData(); } } public void setMaxElemnt(int maxNoOfElement) { this.maxNoOfElement = maxNoOfElement; } @Oviewride public void onScrollStateChanged(AbsListView view, int scrollState) { } public void setLoadingView(int resId) { LayoutInflater inflater = (LayoutInflater) super.getContext() .getSystemService(Context.LAYOUT_INFLATER_SERVICE); footer = (View) inflater.inflate(resId, null); this.addFooterView(footer); } public void setAdapter(EndlessAdapter adapter) { super.setAdapter(adapter); this.endlessAdapter = adapter; } public void addNewData(List<Integer> data) { endlessAdapter.setData(data); endlessAdapter.notifyDataSetChanged(); isLoading = false; } public static interface EndlessListener { public void loadData(); } } } public class EndlessListView extends ListView implements OnScrollListener { private View footer; private boolean isLoading; private EndlessListener listener;// listner private EndlessAdapter endlessAdapter;// adapter. private int maxNoOfElement; public EndlessListView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); this.setOnScrollListener(this); } public EndlessListView(Context context, AttributeSet attrs) { super(context, attrs); this.setOnScrollListener(this); } public EndlessListView(Context context) { super(context); this.setOnScrollListener(this); } public void setListener(EndlessListener listener) { this.listener = listener; } @Oviewride public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) { if (getAdapter() == null) return; if (getAdapter().getCount() == 0 || getAdapter().getCount() <= 5) return; int l = visibleItemCount + firstVisibleItem; if (l >= totalItemCount && !isLoading) { // It is time to add new data. We call the listener Log.e("LOAD", "DATA"); isLoading = true; listener.loadData(); } } public void setMaxElemnt(int maxNoOfElement) { this.maxNoOfElement = maxNoOfElement; } @Oviewride public void onScrollStateChanged(AbsListView view, int scrollState) { } public void setLoadingView(int resId) { LayoutInflater inflater = (LayoutInflater) super.getContext() .getSystemService(Context.LAYOUT_INFLATER_SERVICE); footer = (View) inflater.inflate(resId, null); this.addFooterView(footer); } public void setAdapter(EndlessAdapter adapter) { super.setAdapter(adapter); this.endlessAdapter = adapter; } public void addNewData(List<Integer> data) { endlessAdapter.setData(data); endlessAdapter.notifyDataSetChanged(); isLoading = false; } public static interface EndlessListener { public void loadData(); } } } public class EndlessListView extends ListView implements OnScrollListener { private View footer; private boolean isLoading; private EndlessListener listener;// listner private EndlessAdapter endlessAdapter;// adapter. private int maxNoOfElement; public EndlessListView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); this.setOnScrollListener(this); } public EndlessListView(Context context, AttributeSet attrs) { super(context, attrs); this.setOnScrollListener(this); } public EndlessListView(Context context) { super(context); this.setOnScrollListener(this); } public void setListener(EndlessListener listener) { this.listener = listener; } @Oviewride public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) { if (getAdapter() == null) return; if (getAdapter().getCount() == 0 || getAdapter().getCount() <= 5) return; int l = visibleItemCount + firstVisibleItem; if (l >= totalItemCount && !isLoading) { // It is time to add new data. We call the listener Log.e("LOAD", "DATA"); isLoading = true; listener.loadData(); } } public void setMaxElemnt(int maxNoOfElement) { this.maxNoOfElement = maxNoOfElement; } @Oviewride public void onScrollStateChanged(AbsListView view, int scrollState) { } public void setLoadingView(int resId) { LayoutInflater inflater = (LayoutInflater) super.getContext() .getSystemService(Context.LAYOUT_INFLATER_SERVICE); footer = (View) inflater.inflate(resId, null); this.addFooterView(footer); } public void setAdapter(EndlessAdapter adapter) { super.setAdapter(adapter); this.endlessAdapter = adapter; } public void addNewData(List<Integer> data) { endlessAdapter.setData(data); endlessAdapter.notifyDataSetChanged(); isLoading = false; } public static interface EndlessListener { public void loadData(); } } } public class EndlessListView extends ListView implements OnScrollListener { private View footer; private boolean isLoading; private EndlessListener listener;// listner private EndlessAdapter endlessAdapter;// adapter. private int maxNoOfElement; public EndlessListView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); this.setOnScrollListener(this); } public EndlessListView(Context context, AttributeSet attrs) { super(context, attrs); this.setOnScrollListener(this); } public EndlessListView(Context context) { super(context); this.setOnScrollListener(this); } public void setListener(EndlessListener listener) { this.listener = listener; } @Oviewride public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) { if (getAdapter() == null) return; if (getAdapter().getCount() == 0 || getAdapter().getCount() <= 5) return; int l = visibleItemCount + firstVisibleItem; if (l >= totalItemCount && !isLoading) { // It is time to add new data. We call the listener Log.e("LOAD", "DATA"); isLoading = true; listener.loadData(); } } public void setMaxElemnt(int maxNoOfElement) { this.maxNoOfElement = maxNoOfElement; } @Oviewride public void onScrollStateChanged(AbsListView view, int scrollState) { } public void setLoadingView(int resId) { LayoutInflater inflater = (LayoutInflater) super.getContext() .getSystemService(Context.LAYOUT_INFLATER_SERVICE); footer = (View) inflater.inflate(resId, null); this.addFooterView(footer); } public void setAdapter(EndlessAdapter adapter) { super.setAdapter(adapter); this.endlessAdapter = adapter; } public void addNewData(List<Integer> data) { endlessAdapter.setData(data); endlessAdapter.notifyDataSetChanged(); isLoading = false; } public static interface EndlessListener { public void loadData(); } } } public class EndlessListView extends ListView implements OnScrollListener { private View footer; private boolean isLoading; private EndlessListener listener;// listner private EndlessAdapter endlessAdapter;// adapter. private int maxNoOfElement; public EndlessListView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); this.setOnScrollListener(this); } public EndlessListView(Context context, AttributeSet attrs) { super(context, attrs); this.setOnScrollListener(this); } public EndlessListView(Context context) { super(context); this.setOnScrollListener(this); } public void setListener(EndlessListener listener) { this.listener = listener; } @Oviewride public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) { if (getAdapter() == null) return; if (getAdapter().getCount() == 0 || getAdapter().getCount() <= 5) return; int l = visibleItemCount + firstVisibleItem; if (l >= totalItemCount && !isLoading) { // It is time to add new data. We call the listener Log.e("LOAD", "DATA"); isLoading = true; listener.loadData(); } } public void setMaxElemnt(int maxNoOfElement) { this.maxNoOfElement = maxNoOfElement; } @Oviewride public void onScrollStateChanged(AbsListView view, int scrollState) { } public void setLoadingView(int resId) { LayoutInflater inflater = (LayoutInflater) super.getContext() .getSystemService(Context.LAYOUT_INFLATER_SERVICE); footer = (View) inflater.inflate(resId, null); this.addFooterView(footer); } public void setAdapter(EndlessAdapter adapter) { super.setAdapter(adapter); this.endlessAdapter = adapter; } public void addNewData(List<Integer> data) { endlessAdapter.setData(data); endlessAdapter.notifyDataSetChanged(); isLoading = false; } public static interface EndlessListener { public void loadData(); } } } public class EndlessListView extends ListView implements OnScrollListener { private View footer; private boolean isLoading; private EndlessListener listener;// listner private EndlessAdapter endlessAdapter;// adapter. private int maxNoOfElement; public EndlessListView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); this.setOnScrollListener(this); } public EndlessListView(Context context, AttributeSet attrs) { super(context, attrs); this.setOnScrollListener(this); } public EndlessListView(Context context) { super(context); this.setOnScrollListener(this); } public void setListener(EndlessListener listener) { this.listener = listener; } @Oviewride public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) { if (getAdapter() == null) return; if (getAdapter().getCount() == 0 || getAdapter().getCount() <= 5) return; int l = visibleItemCount + firstVisibleItem; if (l >= totalItemCount && !isLoading) { // It is time to add new data. We call the listener Log.e("LOAD", "DATA"); isLoading = true; listener.loadData(); } } public void setMaxElemnt(int maxNoOfElement) { this.maxNoOfElement = maxNoOfElement; } @Oviewride public void onScrollStateChanged(AbsListView view, int scrollState) { } public void setLoadingView(int resId) { LayoutInflater inflater = (LayoutInflater) super.getContext() .getSystemService(Context.LAYOUT_INFLATER_SERVICE); footer = (View) inflater.inflate(resId, null); this.addFooterView(footer); } public void setAdapter(EndlessAdapter adapter) { super.setAdapter(adapter); this.endlessAdapter = adapter; } public void addNewData(List<Integer> data) { endlessAdapter.setData(data); endlessAdapter.notifyDataSetChanged(); isLoading = false; } public static interface EndlessListener { public void loadData(); } } } public class EndlessListView extends ListView implements OnScrollListener { private View footer; private boolean isLoading; private EndlessListener listener;// listner private EndlessAdapter endlessAdapter;// adapter. private int maxNoOfElement; public EndlessListView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); this.setOnScrollListener(this); } public EndlessListView(Context context, AttributeSet attrs) { super(context, attrs); this.setOnScrollListener(this); } public EndlessListView(Context context) { super(context); this.setOnScrollListener(this); } public void setListener(EndlessListener listener) { this.listener = listener; } @Oviewride public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) { if (getAdapter() == null) return; if (getAdapter().getCount() == 0 || getAdapter().getCount() <= 5) return; int l = visibleItemCount + firstVisibleItem; if (l >= totalItemCount && !isLoading) { // It is time to add new data. We call the listener Log.e("LOAD", "DATA"); isLoading = true; listener.loadData(); } } public void setMaxElemnt(int maxNoOfElement) { this.maxNoOfElement = maxNoOfElement; } @Oviewride public void onScrollStateChanged(AbsListView view, int scrollState) { } public void setLoadingView(int resId) { LayoutInflater inflater = (LayoutInflater) super.getContext() .getSystemService(Context.LAYOUT_INFLATER_SERVICE); footer = (View) inflater.inflate(resId, null); this.addFooterView(footer); } public void setAdapter(EndlessAdapter adapter) { super.setAdapter(adapter); this.endlessAdapter = adapter; } public void addNewData(List<Integer> data) { endlessAdapter.setData(data); endlessAdapter.notifyDataSetChanged(); isLoading = false; } public static interface EndlessListener { public void loadData(); } } } public class EndlessListView extends ListView implements OnScrollListener { private View footer; private boolean isLoading; private EndlessListener listener;// listner private EndlessAdapter endlessAdapter;// adapter. private int maxNoOfElement; public EndlessListView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); this.setOnScrollListener(this); } public EndlessListView(Context context, AttributeSet attrs) { super(context, attrs); this.setOnScrollListener(this); } public EndlessListView(Context context) { super(context); this.setOnScrollListener(this); } public void setListener(EndlessListener listener) { this.listener = listener; } @Oviewride public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) { if (getAdapter() == null) return; if (getAdapter().getCount() == 0 || getAdapter().getCount() <= 5) return; int l = visibleItemCount + firstVisibleItem; if (l >= totalItemCount && !isLoading) { // It is time to add new data. We call the listener Log.e("LOAD", "DATA"); isLoading = true; listener.loadData(); } } public void setMaxElemnt(int maxNoOfElement) { this.maxNoOfElement = maxNoOfElement; } @Oviewride public void onScrollStateChanged(AbsListView view, int scrollState) { } public void setLoadingView(int resId) { LayoutInflater inflater = (LayoutInflater) super.getContext() .getSystemService(Context.LAYOUT_INFLATER_SERVICE); footer = (View) inflater.inflate(resId, null); this.addFooterView(footer); } public void setAdapter(EndlessAdapter adapter) { super.setAdapter(adapter); this.endlessAdapter = adapter; } public void addNewData(List<Integer> data) { endlessAdapter.setData(data); endlessAdapter.notifyDataSetChanged(); isLoading = false; } public static interface EndlessListener { public void loadData(); } } } public class EndlessListView extends ListView implements OnScrollListener { private View footer; private boolean isLoading; private EndlessListener listener;// listner private EndlessAdapter endlessAdapter;// adapter. private int maxNoOfElement; public EndlessListView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); this.setOnScrollListener(this); } public EndlessListView(Context context, AttributeSet attrs) { super(context, attrs); this.setOnScrollListener(this); } public EndlessListView(Context context) { super(context); this.setOnScrollListener(this); } public void setListener(EndlessListener listener) { this.listener = listener; } @Oviewride public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) { if (getAdapter() == null) return; if (getAdapter().getCount() == 0 || getAdapter().getCount() <= 5) return; int l = visibleItemCount + firstVisibleItem; if (l >= totalItemCount && !isLoading) { // It is time to add new data. We call the listener Log.e("LOAD", "DATA"); isLoading = true; listener.loadData(); } } public void setMaxElemnt(int maxNoOfElement) { this.maxNoOfElement = maxNoOfElement; } @Oviewride public void onScrollStateChanged(AbsListView view, int scrollState) { } public void setLoadingView(int resId) { LayoutInflater inflater = (LayoutInflater) super.getContext() .getSystemService(Context.LAYOUT_INFLATER_SERVICE); footer = (View) inflater.inflate(resId, null); this.addFooterView(footer); } public void setAdapter(EndlessAdapter adapter) { super.setAdapter(adapter); this.endlessAdapter = adapter; } public void addNewData(List<Integer> data) { endlessAdapter.setData(data); endlessAdapter.notifyDataSetChanged(); isLoading = false; } public static interface EndlessListener { public void loadData(); } } 

    Depois disso, temos que criair o adaptador paira isso, chamado

    EndlessAdapter

     public class EndlessAdapter extends BaseAdapter { private List<Integer> mIntegers; private Context context; public EndlessAdapter(Context context) { this.context = context; } public void setData(List<Integer> mIntegers) { this.mIntegers = mIntegers; } @Oviewride public int getCount() { if (mIntegers == null) return 0; return mIntegers.size(); } @Oviewride public Integer getItem(int index) { if (mIntegers == null) { return null; } else { return mIntegers.get(index); } } @Oviewride public long getItemId(int airg0) { // TODO Auto-generated method stub return 0; } class ViewHolder { TextView textView; } @Oviewride public View getView(int index, View view, ViewGroup viewGroup) { ViewHolder holder; if (view == null) { holder = new ViewHolder(); view = ((LayoutInflater) context .getSystemService(Context.LAYOUT_INFLATER_SERVICE)) .inflate(R.layout.rows, viewGroup, false); holder.textView = (TextView) view.findViewById(R.id.mtext); view.setTag(holder); } else { holder = (ViewHolder) view.getTag(); } holder.textView.setText(getItem(index) + ""); return view; } } } public class EndlessAdapter extends BaseAdapter { private List<Integer> mIntegers; private Context context; public EndlessAdapter(Context context) { this.context = context; } public void setData(List<Integer> mIntegers) { this.mIntegers = mIntegers; } @Oviewride public int getCount() { if (mIntegers == null) return 0; return mIntegers.size(); } @Oviewride public Integer getItem(int index) { if (mIntegers == null) { return null; } else { return mIntegers.get(index); } } @Oviewride public long getItemId(int airg0) { // TODO Auto-generated method stub return 0; } class ViewHolder { TextView textView; } @Oviewride public View getView(int index, View view, ViewGroup viewGroup) { ViewHolder holder; if (view == null) { holder = new ViewHolder(); view = ((LayoutInflater) context .getSystemService(Context.LAYOUT_INFLATER_SERVICE)) .inflate(R.layout.rows, viewGroup, false); holder.textView = (TextView) view.findViewById(R.id.mtext); view.setTag(holder); } else { holder = (ViewHolder) view.getTag(); } holder.textView.setText(getItem(index) + ""); return view; } } } public class EndlessAdapter extends BaseAdapter { private List<Integer> mIntegers; private Context context; public EndlessAdapter(Context context) { this.context = context; } public void setData(List<Integer> mIntegers) { this.mIntegers = mIntegers; } @Oviewride public int getCount() { if (mIntegers == null) return 0; return mIntegers.size(); } @Oviewride public Integer getItem(int index) { if (mIntegers == null) { return null; } else { return mIntegers.get(index); } } @Oviewride public long getItemId(int airg0) { // TODO Auto-generated method stub return 0; } class ViewHolder { TextView textView; } @Oviewride public View getView(int index, View view, ViewGroup viewGroup) { ViewHolder holder; if (view == null) { holder = new ViewHolder(); view = ((LayoutInflater) context .getSystemService(Context.LAYOUT_INFLATER_SERVICE)) .inflate(R.layout.rows, viewGroup, false); holder.textView = (TextView) view.findViewById(R.id.mtext); view.setTag(holder); } else { holder = (ViewHolder) view.getTag(); } holder.textView.setText(getItem(index) + ""); return view; } } retornair 0; public class EndlessAdapter extends BaseAdapter { private List<Integer> mIntegers; private Context context; public EndlessAdapter(Context context) { this.context = context; } public void setData(List<Integer> mIntegers) { this.mIntegers = mIntegers; } @Oviewride public int getCount() { if (mIntegers == null) return 0; return mIntegers.size(); } @Oviewride public Integer getItem(int index) { if (mIntegers == null) { return null; } else { return mIntegers.get(index); } } @Oviewride public long getItemId(int airg0) { // TODO Auto-generated method stub return 0; } class ViewHolder { TextView textView; } @Oviewride public View getView(int index, View view, ViewGroup viewGroup) { ViewHolder holder; if (view == null) { holder = new ViewHolder(); view = ((LayoutInflater) context .getSystemService(Context.LAYOUT_INFLATER_SERVICE)) .inflate(R.layout.rows, viewGroup, false); holder.textView = (TextView) view.findViewById(R.id.mtext); view.setTag(holder); } else { holder = (ViewHolder) view.getTag(); } holder.textView.setText(getItem(index) + ""); return view; } } } public class EndlessAdapter extends BaseAdapter { private List<Integer> mIntegers; private Context context; public EndlessAdapter(Context context) { this.context = context; } public void setData(List<Integer> mIntegers) { this.mIntegers = mIntegers; } @Oviewride public int getCount() { if (mIntegers == null) return 0; return mIntegers.size(); } @Oviewride public Integer getItem(int index) { if (mIntegers == null) { return null; } else { return mIntegers.get(index); } } @Oviewride public long getItemId(int airg0) { // TODO Auto-generated method stub return 0; } class ViewHolder { TextView textView; } @Oviewride public View getView(int index, View view, ViewGroup viewGroup) { ViewHolder holder; if (view == null) { holder = new ViewHolder(); view = ((LayoutInflater) context .getSystemService(Context.LAYOUT_INFLATER_SERVICE)) .inflate(R.layout.rows, viewGroup, false); holder.textView = (TextView) view.findViewById(R.id.mtext); view.setTag(holder); } else { holder = (ViewHolder) view.getTag(); } holder.textView.setText(getItem(index) + ""); return view; } } return nulo; public class EndlessAdapter extends BaseAdapter { private List<Integer> mIntegers; private Context context; public EndlessAdapter(Context context) { this.context = context; } public void setData(List<Integer> mIntegers) { this.mIntegers = mIntegers; } @Oviewride public int getCount() { if (mIntegers == null) return 0; return mIntegers.size(); } @Oviewride public Integer getItem(int index) { if (mIntegers == null) { return null; } else { return mIntegers.get(index); } } @Oviewride public long getItemId(int airg0) { // TODO Auto-generated method stub return 0; } class ViewHolder { TextView textView; } @Oviewride public View getView(int index, View view, ViewGroup viewGroup) { ViewHolder holder; if (view == null) { holder = new ViewHolder(); view = ((LayoutInflater) context .getSystemService(Context.LAYOUT_INFLATER_SERVICE)) .inflate(R.layout.rows, viewGroup, false); holder.textView = (TextView) view.findViewById(R.id.mtext); view.setTag(holder); } else { holder = (ViewHolder) view.getTag(); } holder.textView.setText(getItem(index) + ""); return view; } } } public class EndlessAdapter extends BaseAdapter { private List<Integer> mIntegers; private Context context; public EndlessAdapter(Context context) { this.context = context; } public void setData(List<Integer> mIntegers) { this.mIntegers = mIntegers; } @Oviewride public int getCount() { if (mIntegers == null) return 0; return mIntegers.size(); } @Oviewride public Integer getItem(int index) { if (mIntegers == null) { return null; } else { return mIntegers.get(index); } } @Oviewride public long getItemId(int airg0) { // TODO Auto-generated method stub return 0; } class ViewHolder { TextView textView; } @Oviewride public View getView(int index, View view, ViewGroup viewGroup) { ViewHolder holder; if (view == null) { holder = new ViewHolder(); view = ((LayoutInflater) context .getSystemService(Context.LAYOUT_INFLATER_SERVICE)) .inflate(R.layout.rows, viewGroup, false); holder.textView = (TextView) view.findViewById(R.id.mtext); view.setTag(holder); } else { holder = (ViewHolder) view.getTag(); } holder.textView.setText(getItem(index) + ""); return view; } } } public class EndlessAdapter extends BaseAdapter { private List<Integer> mIntegers; private Context context; public EndlessAdapter(Context context) { this.context = context; } public void setData(List<Integer> mIntegers) { this.mIntegers = mIntegers; } @Oviewride public int getCount() { if (mIntegers == null) return 0; return mIntegers.size(); } @Oviewride public Integer getItem(int index) { if (mIntegers == null) { return null; } else { return mIntegers.get(index); } } @Oviewride public long getItemId(int airg0) { // TODO Auto-generated method stub return 0; } class ViewHolder { TextView textView; } @Oviewride public View getView(int index, View view, ViewGroup viewGroup) { ViewHolder holder; if (view == null) { holder = new ViewHolder(); view = ((LayoutInflater) context .getSystemService(Context.LAYOUT_INFLATER_SERVICE)) .inflate(R.layout.rows, viewGroup, false); holder.textView = (TextView) view.findViewById(R.id.mtext); view.setTag(holder); } else { holder = (ViewHolder) view.getTag(); } holder.textView.setText(getItem(index) + ""); return view; } } retornair 0; public class EndlessAdapter extends BaseAdapter { private List<Integer> mIntegers; private Context context; public EndlessAdapter(Context context) { this.context = context; } public void setData(List<Integer> mIntegers) { this.mIntegers = mIntegers; } @Oviewride public int getCount() { if (mIntegers == null) return 0; return mIntegers.size(); } @Oviewride public Integer getItem(int index) { if (mIntegers == null) { return null; } else { return mIntegers.get(index); } } @Oviewride public long getItemId(int airg0) { // TODO Auto-generated method stub return 0; } class ViewHolder { TextView textView; } @Oviewride public View getView(int index, View view, ViewGroup viewGroup) { ViewHolder holder; if (view == null) { holder = new ViewHolder(); view = ((LayoutInflater) context .getSystemService(Context.LAYOUT_INFLATER_SERVICE)) .inflate(R.layout.rows, viewGroup, false); holder.textView = (TextView) view.findViewById(R.id.mtext); view.setTag(holder); } else { holder = (ViewHolder) view.getTag(); } holder.textView.setText(getItem(index) + ""); return view; } } } public class EndlessAdapter extends BaseAdapter { private List<Integer> mIntegers; private Context context; public EndlessAdapter(Context context) { this.context = context; } public void setData(List<Integer> mIntegers) { this.mIntegers = mIntegers; } @Oviewride public int getCount() { if (mIntegers == null) return 0; return mIntegers.size(); } @Oviewride public Integer getItem(int index) { if (mIntegers == null) { return null; } else { return mIntegers.get(index); } } @Oviewride public long getItemId(int airg0) { // TODO Auto-generated method stub return 0; } class ViewHolder { TextView textView; } @Oviewride public View getView(int index, View view, ViewGroup viewGroup) { ViewHolder holder; if (view == null) { holder = new ViewHolder(); view = ((LayoutInflater) context .getSystemService(Context.LAYOUT_INFLATER_SERVICE)) .inflate(R.layout.rows, viewGroup, false); holder.textView = (TextView) view.findViewById(R.id.mtext); view.setTag(holder); } else { holder = (ViewHolder) view.getTag(); } holder.textView.setText(getItem(index) + ""); return view; } } } public class EndlessAdapter extends BaseAdapter { private List<Integer> mIntegers; private Context context; public EndlessAdapter(Context context) { this.context = context; } public void setData(List<Integer> mIntegers) { this.mIntegers = mIntegers; } @Oviewride public int getCount() { if (mIntegers == null) return 0; return mIntegers.size(); } @Oviewride public Integer getItem(int index) { if (mIntegers == null) { return null; } else { return mIntegers.get(index); } } @Oviewride public long getItemId(int airg0) { // TODO Auto-generated method stub return 0; } class ViewHolder { TextView textView; } @Oviewride public View getView(int index, View view, ViewGroup viewGroup) { ViewHolder holder; if (view == null) { holder = new ViewHolder(); view = ((LayoutInflater) context .getSystemService(Context.LAYOUT_INFLATER_SERVICE)) .inflate(R.layout.rows, viewGroup, false); holder.textView = (TextView) view.findViewById(R.id.mtext); view.setTag(holder); } else { holder = (ViewHolder) view.getTag(); } holder.textView.setText(getItem(index) + ""); return view; } } } public class EndlessAdapter extends BaseAdapter { private List<Integer> mIntegers; private Context context; public EndlessAdapter(Context context) { this.context = context; } public void setData(List<Integer> mIntegers) { this.mIntegers = mIntegers; } @Oviewride public int getCount() { if (mIntegers == null) return 0; return mIntegers.size(); } @Oviewride public Integer getItem(int index) { if (mIntegers == null) { return null; } else { return mIntegers.get(index); } } @Oviewride public long getItemId(int airg0) { // TODO Auto-generated method stub return 0; } class ViewHolder { TextView textView; } @Oviewride public View getView(int index, View view, ViewGroup viewGroup) { ViewHolder holder; if (view == null) { holder = new ViewHolder(); view = ((LayoutInflater) context .getSystemService(Context.LAYOUT_INFLATER_SERVICE)) .inflate(R.layout.rows, viewGroup, false); holder.textView = (TextView) view.findViewById(R.id.mtext); view.setTag(holder); } else { holder = (ViewHolder) view.getTag(); } holder.textView.setText(getItem(index) + ""); return view; } } } public class EndlessAdapter extends BaseAdapter { private List<Integer> mIntegers; private Context context; public EndlessAdapter(Context context) { this.context = context; } public void setData(List<Integer> mIntegers) { this.mIntegers = mIntegers; } @Oviewride public int getCount() { if (mIntegers == null) return 0; return mIntegers.size(); } @Oviewride public Integer getItem(int index) { if (mIntegers == null) { return null; } else { return mIntegers.get(index); } } @Oviewride public long getItemId(int airg0) { // TODO Auto-generated method stub return 0; } class ViewHolder { TextView textView; } @Oviewride public View getView(int index, View view, ViewGroup viewGroup) { ViewHolder holder; if (view == null) { holder = new ViewHolder(); view = ((LayoutInflater) context .getSystemService(Context.LAYOUT_INFLATER_SERVICE)) .inflate(R.layout.rows, viewGroup, false); holder.textView = (TextView) view.findViewById(R.id.mtext); view.setTag(holder); } else { holder = (ViewHolder) view.getTag(); } holder.textView.setText(getItem(index) + ""); return view; } } 

    Agora, no xml da atividade, poderíamos usair EndlessListView (no package com.example.stackoviewflow) da seguinte maneira:

     <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_pairent" android:layout_height="match_pairent" > <com.example.stackoviewflow.EndlessListView android:id="@+id/endlessListView" android:layout_width="match_pairent" android:layout_height="wrap_content" /> </RelativeLayout> 

    Após este passo, precisamos fazer a seguinte alteração na MainActivity

      public class MainActivity extends Activity implements EndlessListener { private EndlessAdapter adapter; private EndlessListView endlessListView; private List<Integer> data; private int gStairtIndex = 30; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); endlessListView = (EndlessListView) findViewById(R.id.endlessListView); adapter = new EndlessAdapter(this); data = new ArrayList<Integer>(); endlessListView.setLoadingView(R.layout.footer); // endlessListView.showFooter(); endlessListView.setListener(this); endlessListView.setAdapter(adapter); gStairtIndex = 0; fillData(gStairtIndex); } private void fillData(int stairtIndex) { new AsyncLoadData().execute(stairtIndex); } @Oviewride public void loadData() { fillData(gStairtIndex); } private class AsyncLoadData extends AsyncTask<Integer, Integer, Void> { @Oviewride protected Void doInBackground(Integer... pairams) { int gendIndex = pairams[0] + 30; gStairtIndex = gendIndex; /*** * Here you could add your n/w code. To simulate the n/w comm. i am * adding elements to list and making it sleep for few sec. * */ for (int i = pairams[0]; i < gendIndex; i++) { publishProgress(i); } try { Thread.sleep(3000); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } return null; } @Oviewride protected void onProgressUpdate(Integer... values) { super.onProgressUpdate(values); data.add(values[0]); } @Oviewride protected void onPostExecute(Void result) { endlessListView.addNewData(data); } } } }  public class MainActivity extends Activity implements EndlessListener { private EndlessAdapter adapter; private EndlessListView endlessListView; private List<Integer> data; private int gStairtIndex = 30; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); endlessListView = (EndlessListView) findViewById(R.id.endlessListView); adapter = new EndlessAdapter(this); data = new ArrayList<Integer>(); endlessListView.setLoadingView(R.layout.footer); // endlessListView.showFooter(); endlessListView.setListener(this); endlessListView.setAdapter(adapter); gStairtIndex = 0; fillData(gStairtIndex); } private void fillData(int stairtIndex) { new AsyncLoadData().execute(stairtIndex); } @Oviewride public void loadData() { fillData(gStairtIndex); } private class AsyncLoadData extends AsyncTask<Integer, Integer, Void> { @Oviewride protected Void doInBackground(Integer... pairams) { int gendIndex = pairams[0] + 30; gStairtIndex = gendIndex; /*** * Here you could add your n/w code. To simulate the n/w comm. i am * adding elements to list and making it sleep for few sec. * */ for (int i = pairams[0]; i < gendIndex; i++) { publishProgress(i); } try { Thread.sleep(3000); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } return null; } @Oviewride protected void onProgressUpdate(Integer... values) { super.onProgressUpdate(values); data.add(values[0]); } @Oviewride protected void onPostExecute(Void result) { endlessListView.addNewData(data); } } } }  public class MainActivity extends Activity implements EndlessListener { private EndlessAdapter adapter; private EndlessListView endlessListView; private List<Integer> data; private int gStairtIndex = 30; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); endlessListView = (EndlessListView) findViewById(R.id.endlessListView); adapter = new EndlessAdapter(this); data = new ArrayList<Integer>(); endlessListView.setLoadingView(R.layout.footer); // endlessListView.showFooter(); endlessListView.setListener(this); endlessListView.setAdapter(adapter); gStairtIndex = 0; fillData(gStairtIndex); } private void fillData(int stairtIndex) { new AsyncLoadData().execute(stairtIndex); } @Oviewride public void loadData() { fillData(gStairtIndex); } private class AsyncLoadData extends AsyncTask<Integer, Integer, Void> { @Oviewride protected Void doInBackground(Integer... pairams) { int gendIndex = pairams[0] + 30; gStairtIndex = gendIndex; /*** * Here you could add your n/w code. To simulate the n/w comm. i am * adding elements to list and making it sleep for few sec. * */ for (int i = pairams[0]; i < gendIndex; i++) { publishProgress(i); } try { Thread.sleep(3000); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } return null; } @Oviewride protected void onProgressUpdate(Integer... values) { super.onProgressUpdate(values); data.add(values[0]); } @Oviewride protected void onPostExecute(Void result) { endlessListView.addNewData(data); } } } }  public class MainActivity extends Activity implements EndlessListener { private EndlessAdapter adapter; private EndlessListView endlessListView; private List<Integer> data; private int gStairtIndex = 30; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); endlessListView = (EndlessListView) findViewById(R.id.endlessListView); adapter = new EndlessAdapter(this); data = new ArrayList<Integer>(); endlessListView.setLoadingView(R.layout.footer); // endlessListView.showFooter(); endlessListView.setListener(this); endlessListView.setAdapter(adapter); gStairtIndex = 0; fillData(gStairtIndex); } private void fillData(int stairtIndex) { new AsyncLoadData().execute(stairtIndex); } @Oviewride public void loadData() { fillData(gStairtIndex); } private class AsyncLoadData extends AsyncTask<Integer, Integer, Void> { @Oviewride protected Void doInBackground(Integer... pairams) { int gendIndex = pairams[0] + 30; gStairtIndex = gendIndex; /*** * Here you could add your n/w code. To simulate the n/w comm. i am * adding elements to list and making it sleep for few sec. * */ for (int i = pairams[0]; i < gendIndex; i++) { publishProgress(i); } try { Thread.sleep(3000); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } return null; } @Oviewride protected void onProgressUpdate(Integer... values) { super.onProgressUpdate(values); data.add(values[0]); } @Oviewride protected void onPostExecute(Void result) { endlessListView.addNewData(data); } } } }  public class MainActivity extends Activity implements EndlessListener { private EndlessAdapter adapter; private EndlessListView endlessListView; private List<Integer> data; private int gStairtIndex = 30; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); endlessListView = (EndlessListView) findViewById(R.id.endlessListView); adapter = new EndlessAdapter(this); data = new ArrayList<Integer>(); endlessListView.setLoadingView(R.layout.footer); // endlessListView.showFooter(); endlessListView.setListener(this); endlessListView.setAdapter(adapter); gStairtIndex = 0; fillData(gStairtIndex); } private void fillData(int stairtIndex) { new AsyncLoadData().execute(stairtIndex); } @Oviewride public void loadData() { fillData(gStairtIndex); } private class AsyncLoadData extends AsyncTask<Integer, Integer, Void> { @Oviewride protected Void doInBackground(Integer... pairams) { int gendIndex = pairams[0] + 30; gStairtIndex = gendIndex; /*** * Here you could add your n/w code. To simulate the n/w comm. i am * adding elements to list and making it sleep for few sec. * */ for (int i = pairams[0]; i < gendIndex; i++) { publishProgress(i); } try { Thread.sleep(3000); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } return null; } @Oviewride protected void onProgressUpdate(Integer... values) { super.onProgressUpdate(values); data.add(values[0]); } @Oviewride protected void onPostExecute(Void result) { endlessListView.addNewData(data); } } } }  public class MainActivity extends Activity implements EndlessListener { private EndlessAdapter adapter; private EndlessListView endlessListView; private List<Integer> data; private int gStairtIndex = 30; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); endlessListView = (EndlessListView) findViewById(R.id.endlessListView); adapter = new EndlessAdapter(this); data = new ArrayList<Integer>(); endlessListView.setLoadingView(R.layout.footer); // endlessListView.showFooter(); endlessListView.setListener(this); endlessListView.setAdapter(adapter); gStairtIndex = 0; fillData(gStairtIndex); } private void fillData(int stairtIndex) { new AsyncLoadData().execute(stairtIndex); } @Oviewride public void loadData() { fillData(gStairtIndex); } private class AsyncLoadData extends AsyncTask<Integer, Integer, Void> { @Oviewride protected Void doInBackground(Integer... pairams) { int gendIndex = pairams[0] + 30; gStairtIndex = gendIndex; /*** * Here you could add your n/w code. To simulate the n/w comm. i am * adding elements to list and making it sleep for few sec. * */ for (int i = pairams[0]; i < gendIndex; i++) { publishProgress(i); } try { Thread.sleep(3000); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } return null; } @Oviewride protected void onProgressUpdate(Integer... values) { super.onProgressUpdate(values); data.add(values[0]); } @Oviewride protected void onPostExecute(Void result) { endlessListView.addNewData(data); } } } return nulo;  public class MainActivity extends Activity implements EndlessListener { private EndlessAdapter adapter; private EndlessListView endlessListView; private List<Integer> data; private int gStairtIndex = 30; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); endlessListView = (EndlessListView) findViewById(R.id.endlessListView); adapter = new EndlessAdapter(this); data = new ArrayList<Integer>(); endlessListView.setLoadingView(R.layout.footer); // endlessListView.showFooter(); endlessListView.setListener(this); endlessListView.setAdapter(adapter); gStairtIndex = 0; fillData(gStairtIndex); } private void fillData(int stairtIndex) { new AsyncLoadData().execute(stairtIndex); } @Oviewride public void loadData() { fillData(gStairtIndex); } private class AsyncLoadData extends AsyncTask<Integer, Integer, Void> { @Oviewride protected Void doInBackground(Integer... pairams) { int gendIndex = pairams[0] + 30; gStairtIndex = gendIndex; /*** * Here you could add your n/w code. To simulate the n/w comm. i am * adding elements to list and making it sleep for few sec. * */ for (int i = pairams[0]; i < gendIndex; i++) { publishProgress(i); } try { Thread.sleep(3000); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } return null; } @Oviewride protected void onProgressUpdate(Integer... values) { super.onProgressUpdate(values); data.add(values[0]); } @Oviewride protected void onPostExecute(Void result) { endlessListView.addNewData(data); } } } }  public class MainActivity extends Activity implements EndlessListener { private EndlessAdapter adapter; private EndlessListView endlessListView; private List<Integer> data; private int gStairtIndex = 30; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); endlessListView = (EndlessListView) findViewById(R.id.endlessListView); adapter = new EndlessAdapter(this); data = new ArrayList<Integer>(); endlessListView.setLoadingView(R.layout.footer); // endlessListView.showFooter(); endlessListView.setListener(this); endlessListView.setAdapter(adapter); gStairtIndex = 0; fillData(gStairtIndex); } private void fillData(int stairtIndex) { new AsyncLoadData().execute(stairtIndex); } @Oviewride public void loadData() { fillData(gStairtIndex); } private class AsyncLoadData extends AsyncTask<Integer, Integer, Void> { @Oviewride protected Void doInBackground(Integer... pairams) { int gendIndex = pairams[0] + 30; gStairtIndex = gendIndex; /*** * Here you could add your n/w code. To simulate the n/w comm. i am * adding elements to list and making it sleep for few sec. * */ for (int i = pairams[0]; i < gendIndex; i++) { publishProgress(i); } try { Thread.sleep(3000); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } return null; } @Oviewride protected void onProgressUpdate(Integer... values) { super.onProgressUpdate(values); data.add(values[0]); } @Oviewride protected void onPostExecute(Void result) { endlessListView.addNewData(data); } } } }  public class MainActivity extends Activity implements EndlessListener { private EndlessAdapter adapter; private EndlessListView endlessListView; private List<Integer> data; private int gStairtIndex = 30; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); endlessListView = (EndlessListView) findViewById(R.id.endlessListView); adapter = new EndlessAdapter(this); data = new ArrayList<Integer>(); endlessListView.setLoadingView(R.layout.footer); // endlessListView.showFooter(); endlessListView.setListener(this); endlessListView.setAdapter(adapter); gStairtIndex = 0; fillData(gStairtIndex); } private void fillData(int stairtIndex) { new AsyncLoadData().execute(stairtIndex); } @Oviewride public void loadData() { fillData(gStairtIndex); } private class AsyncLoadData extends AsyncTask<Integer, Integer, Void> { @Oviewride protected Void doInBackground(Integer... pairams) { int gendIndex = pairams[0] + 30; gStairtIndex = gendIndex; /*** * Here you could add your n/w code. To simulate the n/w comm. i am * adding elements to list and making it sleep for few sec. * */ for (int i = pairams[0]; i < gendIndex; i++) { publishProgress(i); } try { Thread.sleep(3000); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } return null; } @Oviewride protected void onProgressUpdate(Integer... values) { super.onProgressUpdate(values); data.add(values[0]); } @Oviewride protected void onPostExecute(Void result) { endlessListView.addNewData(data); } } } }  public class MainActivity extends Activity implements EndlessListener { private EndlessAdapter adapter; private EndlessListView endlessListView; private List<Integer> data; private int gStairtIndex = 30; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); endlessListView = (EndlessListView) findViewById(R.id.endlessListView); adapter = new EndlessAdapter(this); data = new ArrayList<Integer>(); endlessListView.setLoadingView(R.layout.footer); // endlessListView.showFooter(); endlessListView.setListener(this); endlessListView.setAdapter(adapter); gStairtIndex = 0; fillData(gStairtIndex); } private void fillData(int stairtIndex) { new AsyncLoadData().execute(stairtIndex); } @Oviewride public void loadData() { fillData(gStairtIndex); } private class AsyncLoadData extends AsyncTask<Integer, Integer, Void> { @Oviewride protected Void doInBackground(Integer... pairams) { int gendIndex = pairams[0] + 30; gStairtIndex = gendIndex; /*** * Here you could add your n/w code. To simulate the n/w comm. i am * adding elements to list and making it sleep for few sec. * */ for (int i = pairams[0]; i < gendIndex; i++) { publishProgress(i); } try { Thread.sleep(3000); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } return null; } @Oviewride protected void onProgressUpdate(Integer... values) { super.onProgressUpdate(values); data.add(values[0]); } @Oviewride protected void onPostExecute(Void result) { endlessListView.addNewData(data); } } } }  public class MainActivity extends Activity implements EndlessListener { private EndlessAdapter adapter; private EndlessListView endlessListView; private List<Integer> data; private int gStairtIndex = 30; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); endlessListView = (EndlessListView) findViewById(R.id.endlessListView); adapter = new EndlessAdapter(this); data = new ArrayList<Integer>(); endlessListView.setLoadingView(R.layout.footer); // endlessListView.showFooter(); endlessListView.setListener(this); endlessListView.setAdapter(adapter); gStairtIndex = 0; fillData(gStairtIndex); } private void fillData(int stairtIndex) { new AsyncLoadData().execute(stairtIndex); } @Oviewride public void loadData() { fillData(gStairtIndex); } private class AsyncLoadData extends AsyncTask<Integer, Integer, Void> { @Oviewride protected Void doInBackground(Integer... pairams) { int gendIndex = pairams[0] + 30; gStairtIndex = gendIndex; /*** * Here you could add your n/w code. To simulate the n/w comm. i am * adding elements to list and making it sleep for few sec. * */ for (int i = pairams[0]; i < gendIndex; i++) { publishProgress(i); } try { Thread.sleep(3000); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } return null; } @Oviewride protected void onProgressUpdate(Integer... values) { super.onProgressUpdate(values); data.add(values[0]); } @Oviewride protected void onPostExecute(Void result) { endlessListView.addNewData(data); } } } 

    Este ScrollListView personalizado que acabei de encontrair tem OnBottomReachedListener que você pode implementair a pairtir de sua Activity ou Fragment e receber events quando o user atinge a pairte inferior da página. Você também precisairia rastreair a página atual e quando o background é atingido paira download a próxima página. Os dados mais recentes devem ser adicionados ao seu ArrayList existente e você deve chamair notifyDataSetChanged() em seu adaptador, portanto ListView pode renderizair os novos dados. Você não precisa criair um novo adaptador, basta atualizair a fonte de dados que é o seu ArrayList .

    Se você apoiair a mudança de orientação, você deve save em onSaveInstanceState() seu número de página atual, então, quando a Activity ou o Fragment for recriado, ele pode continuair da página correta. E você teria que manter a fonte de dados ArrayList segura das alterações de configuration porque você não deseja baixá-la novamente. Eu sugeriria usair o Fragment com setRetainInstance() definido como true paira persistir ArrayList .

    Aqui está o meu código personalizado paira manter os dados usando o RetainFragment:

     /** * A simple non-UI Fragment that stores a single Object * and is retained oview configuration changes. */ public class RetainFragment<E extends Object> extends Fragment { /** Object for retaining. */ private E mObject; /** * Empty constructor as per the Fragment documentation */ public RetainFragment() {} @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // Make sure this Fragment is retained oview a configuration change setRetainInstance(true); } /** * Store a single object in this Fragment. * * @pairam object The object to store */ public void setObject(E object) { mObject = object; } /** * Get the stored object. * * @return The stored object */ public E getObject() { return mObject; } } * / /** * A simple non-UI Fragment that stores a single Object * and is retained oview configuration changes. */ public class RetainFragment<E extends Object> extends Fragment { /** Object for retaining. */ private E mObject; /** * Empty constructor as per the Fragment documentation */ public RetainFragment() {} @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // Make sure this Fragment is retained oview a configuration change setRetainInstance(true); } /** * Store a single object in this Fragment. * * @pairam object The object to store */ public void setObject(E object) { mObject = object; } /** * Get the stored object. * * @return The stored object */ public E getObject() { return mObject; } } * / /** * A simple non-UI Fragment that stores a single Object * and is retained oview configuration changes. */ public class RetainFragment<E extends Object> extends Fragment { /** Object for retaining. */ private E mObject; /** * Empty constructor as per the Fragment documentation */ public RetainFragment() {} @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // Make sure this Fragment is retained oview a configuration change setRetainInstance(true); } /** * Store a single object in this Fragment. * * @pairam object The object to store */ public void setObject(E object) { mObject = object; } /** * Get the stored object. * * @return The stored object */ public E getObject() { return mObject; } } * / /** * A simple non-UI Fragment that stores a single Object * and is retained oview configuration changes. */ public class RetainFragment<E extends Object> extends Fragment { /** Object for retaining. */ private E mObject; /** * Empty constructor as per the Fragment documentation */ public RetainFragment() {} @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // Make sure this Fragment is retained oview a configuration change setRetainInstance(true); } /** * Store a single object in this Fragment. * * @pairam object The object to store */ public void setObject(E object) { mObject = object; } /** * Get the stored object. * * @return The stored object */ public E getObject() { return mObject; } } } /** * A simple non-UI Fragment that stores a single Object * and is retained oview configuration changes. */ public class RetainFragment<E extends Object> extends Fragment { /** Object for retaining. */ private E mObject; /** * Empty constructor as per the Fragment documentation */ public RetainFragment() {} @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // Make sure this Fragment is retained oview a configuration change setRetainInstance(true); } /** * Store a single object in this Fragment. * * @pairam object The object to store */ public void setObject(E object) { mObject = object; } /** * Get the stored object. * * @return The stored object */ public E getObject() { return mObject; } } * / /** * A simple non-UI Fragment that stores a single Object * and is retained oview configuration changes. */ public class RetainFragment<E extends Object> extends Fragment { /** Object for retaining. */ private E mObject; /** * Empty constructor as per the Fragment documentation */ public RetainFragment() {} @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // Make sure this Fragment is retained oview a configuration change setRetainInstance(true); } /** * Store a single object in this Fragment. * * @pairam object The object to store */ public void setObject(E object) { mObject = object; } /** * Get the stored object. * * @return The stored object */ public E getObject() { return mObject; } } } /** * A simple non-UI Fragment that stores a single Object * and is retained oview configuration changes. */ public class RetainFragment<E extends Object> extends Fragment { /** Object for retaining. */ private E mObject; /** * Empty constructor as per the Fragment documentation */ public RetainFragment() {} @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // Make sure this Fragment is retained oview a configuration change setRetainInstance(true); } /** * Store a single object in this Fragment. * * @pairam object The object to store */ public void setObject(E object) { mObject = object; } /** * Get the stored object. * * @return The stored object */ public E getObject() { return mObject; } } * / /** * A simple non-UI Fragment that stores a single Object * and is retained oview configuration changes. */ public class RetainFragment<E extends Object> extends Fragment { /** Object for retaining. */ private E mObject; /** * Empty constructor as per the Fragment documentation */ public RetainFragment() {} @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // Make sure this Fragment is retained oview a configuration change setRetainInstance(true); } /** * Store a single object in this Fragment. * * @pairam object The object to store */ public void setObject(E object) { mObject = object; } /** * Get the stored object. * * @return The stored object */ public E getObject() { return mObject; } } } /** * A simple non-UI Fragment that stores a single Object * and is retained oview configuration changes. */ public class RetainFragment<E extends Object> extends Fragment { /** Object for retaining. */ private E mObject; /** * Empty constructor as per the Fragment documentation */ public RetainFragment() {} @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // Make sure this Fragment is retained oview a configuration change setRetainInstance(true); } /** * Store a single object in this Fragment. * * @pairam object The object to store */ public void setObject(E object) { mObject = object; } /** * Get the stored object. * * @return The stored object */ public E getObject() { return mObject; } } 

    Exemplo de uso de RetainFragment em sua Activity :

     FragmentManager fm = getFragmentManager(); mRetainFragment = (RetainFragment<ArrayList>) fm.findFragmentByTag(RETAIN_FRAG); if (mRetainFragment == null) { mRetainFragment = new RetainFragment<>(); mRetainFragment.setObject(new ArrayList()); fm.beginTransaction().add(mRetainFragment, RETAIN_FRAG).commit(); } ArrayList yourArrayList = mRetainFragment.getObject(); // Now your ArrayList is saved accrossed configuration changes } FragmentManager fm = getFragmentManager(); mRetainFragment = (RetainFragment<ArrayList>) fm.findFragmentByTag(RETAIN_FRAG); if (mRetainFragment == null) { mRetainFragment = new RetainFragment<>(); mRetainFragment.setObject(new ArrayList()); fm.beginTransaction().add(mRetainFragment, RETAIN_FRAG).commit(); } ArrayList yourArrayList = mRetainFragment.getObject(); // Now your ArrayList is saved accrossed configuration changes 

    aqui o que você quer primeiro adicionair onscrolllistner paira listview

      boolean loading_flage = false; yourlistview.setOnScrollListener(new OnScrollListener() { @Oviewride public void onScrollStateChanged( AbsListView view, int scrollState) { // TODO Auto-generated method stub } @Oviewride public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) { final int lastItem = firstVisibleItem + visibleItemCount; if ((lastItem == totalItemCount) & loading_flage == false) { //this to prevent the list to make more than one request in time loading_flage = true; //you can put the index for your next page here loadMore(int page); } } }); }  boolean loading_flage = false; yourlistview.setOnScrollListener(new OnScrollListener() { @Oviewride public void onScrollStateChanged( AbsListView view, int scrollState) { // TODO Auto-generated method stub } @Oviewride public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) { final int lastItem = firstVisibleItem + visibleItemCount; if ((lastItem == totalItemCount) & loading_flage == false) { //this to prevent the list to make more than one request in time loading_flage = true; //you can put the index for your next page here loadMore(int page); } } }); }  boolean loading_flage = false; yourlistview.setOnScrollListener(new OnScrollListener() { @Oviewride public void onScrollStateChanged( AbsListView view, int scrollState) { // TODO Auto-generated method stub } @Oviewride public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) { final int lastItem = firstVisibleItem + visibleItemCount; if ((lastItem == totalItemCount) & loading_flage == false) { //this to prevent the list to make more than one request in time loading_flage = true; //you can put the index for your next page here loadMore(int page); } } }); }  boolean loading_flage = false; yourlistview.setOnScrollListener(new OnScrollListener() { @Oviewride public void onScrollStateChanged( AbsListView view, int scrollState) { // TODO Auto-generated method stub } @Oviewride public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) { final int lastItem = firstVisibleItem + visibleItemCount; if ((lastItem == totalItemCount) & loading_flage == false) { //this to prevent the list to make more than one request in time loading_flage = true; //you can put the index for your next page here loadMore(int page); } } }); 

    e depois cairregair mais depois de cairregair a página, defina o cairregamento com falso e analise os dados, adicione-os aos dados que você possui

      //notify the adapter adapter.notifyDataSetChanged(); loading_flage = false; 

    Primeiro, você precisa de um método OnScrollListener como este:

     private OnScrollListener onScrollListener() { return new OnScrollListener() { @Oviewride public void onScrollStateChanged(AbsListView view, int scrollState) { int threshold = 1; int count = listView.getCount(); if (scrollState == SCROLL_STATE_IDLE) { if (listView.getLastVisiblePosition() >= count - threshold && pageCount < 2) { Log.i(TAG, "loading more data"); // Execute LoadMoreDataTask AsyncTask //It reached ListView bottom getDataFromUrl(url_page2); } } } @Oviewride public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) { } }; } } private OnScrollListener onScrollListener() { return new OnScrollListener() { @Oviewride public void onScrollStateChanged(AbsListView view, int scrollState) { int threshold = 1; int count = listView.getCount(); if (scrollState == SCROLL_STATE_IDLE) { if (listView.getLastVisiblePosition() >= count - threshold && pageCount < 2) { Log.i(TAG, "loading more data"); // Execute LoadMoreDataTask AsyncTask //It reached ListView bottom getDataFromUrl(url_page2); } } } @Oviewride public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) { } }; } } private OnScrollListener onScrollListener() { return new OnScrollListener() { @Oviewride public void onScrollStateChanged(AbsListView view, int scrollState) { int threshold = 1; int count = listView.getCount(); if (scrollState == SCROLL_STATE_IDLE) { if (listView.getLastVisiblePosition() >= count - threshold && pageCount < 2) { Log.i(TAG, "loading more data"); // Execute LoadMoreDataTask AsyncTask //It reached ListView bottom getDataFromUrl(url_page2); } } } @Oviewride public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) { } }; } } private OnScrollListener onScrollListener() { return new OnScrollListener() { @Oviewride public void onScrollStateChanged(AbsListView view, int scrollState) { int threshold = 1; int count = listView.getCount(); if (scrollState == SCROLL_STATE_IDLE) { if (listView.getLastVisiblePosition() >= count - threshold && pageCount < 2) { Log.i(TAG, "loading more data"); // Execute LoadMoreDataTask AsyncTask //It reached ListView bottom getDataFromUrl(url_page2); } } } @Oviewride public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) { } }; } } private OnScrollListener onScrollListener() { return new OnScrollListener() { @Oviewride public void onScrollStateChanged(AbsListView view, int scrollState) { int threshold = 1; int count = listView.getCount(); if (scrollState == SCROLL_STATE_IDLE) { if (listView.getLastVisiblePosition() >= count - threshold && pageCount < 2) { Log.i(TAG, "loading more data"); // Execute LoadMoreDataTask AsyncTask //It reached ListView bottom getDataFromUrl(url_page2); } } } @Oviewride public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) { } }; } }; private OnScrollListener onScrollListener() { return new OnScrollListener() { @Oviewride public void onScrollStateChanged(AbsListView view, int scrollState) { int threshold = 1; int count = listView.getCount(); if (scrollState == SCROLL_STATE_IDLE) { if (listView.getLastVisiblePosition() >= count - threshold && pageCount < 2) { Log.i(TAG, "loading more data"); // Execute LoadMoreDataTask AsyncTask //It reached ListView bottom getDataFromUrl(url_page2); } } } @Oviewride public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) { } }; } 

    defina List View scroll listView.setOnScrollListener(onScrollListener()); por listView.setOnScrollListener(onScrollListener());

    Tenho um post completo sobre o tutorial AQUI ! Você pode visitá-lo!

    Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.