2011-12-21 63 views

回答

4

尝试这种::

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 >= 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; 
     } 
    } 
} 
+0

更多:: HTTP://stackoverflow.com/questions/1080811/android-endless-list – 2011-12-21 08:06:40

+0

感谢Dr.nik!我在这里发现了一篇文章http://codinglines.frankiv.me/post/14552677846/android-implementing-a-dynamically-loading-adapter – yfranz 2011-12-21 22:40:24

-2

这是listView的默认行为。只有在项目可见时才会加载项目中的视图。

相关问题