Skip to main content

Jul
28
2010

  •   5  down vote accepted 
          

    One solution is to implement an OnScrollListener and make changes (like adding items, etc.) to the ListAdapter at a convenient state in its onScrollStateChanged method.

      

    The following ListActivity shows a list of integers, starting with 40, adding 10 per scroll-stop.

  • 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 v, int i, int j, int k) { }

       
    public void onScrollStateChanged(AbsListView v, int state) {
           
    if(state == OnScrollListener.SCROLL_STATE_IDLE) {
                    adapter
    .count += 10;
                    adapter
    .notifyDataSetChanged();
           
    }
       
    }

       
    class Aleph0 extends BaseAdapter {
           
    int count = 40;

           
    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;
           
    }
       
    }
    }
  • 1 more annotation(s)...
1 - 5 of 5
Showing 20 items per page

Diigo is about better ways to research, share and collaborate on information. Learn more »

Join Diigo
Move to top