Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>One solution is to implement an <a href="http://developer.android.com/reference/android/widget/AbsListView.OnScrollListener.html" rel="noreferrer"><code>OnScrollListener</code></a> and make changes (like adding items, etc.) to the <a href="http://developer.android.com/reference/android/widget/ListAdapter.html" rel="noreferrer"><code>ListAdapter</code></a> at a convenient state in its <code>onScroll</code> method.</p> <p>The following <code>ListActivity</code> shows a list of integers, starting with 40, adding items when the user scrolls to the end of the list.</p> <pre><code>public class Test extends ListActivity implements OnScrollListener { Aleph0 adapter = new Aleph0(); protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setListAdapter(adapter); getListView().setOnScrollListener(this); } public void onScroll(AbsListView view, int firstVisible, int visibleCount, int totalCount) { boolean loadMore = /* maybe add a padding */ firstVisible + visibleCount &gt;= totalCount; if(loadMore) { adapter.count += visibleCount; // or any other amount adapter.notifyDataSetChanged(); } } public void onScrollStateChanged(AbsListView v, int s) { } class Aleph0 extends BaseAdapter { int count = 40; /* starting amount */ public int getCount() { return count; } public Object getItem(int pos) { return pos; } public long getItemId(int pos) { return pos; } public View getView(int pos, View v, ViewGroup p) { TextView view = new TextView(Test.this); view.setText("entry " + pos); return view; } } } </code></pre> <p>You should obviously use separate threads for long running actions (like loading web-data) and might want to indicate progress in the last list item (like the market or gmail apps do).</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload