2013-09-25 32 views
0

我想做一个列表视图,当用户滚动到列表视图的底部其他项目的列表自动填充internet.I编写代码到该可扩展列表视图的适配器(在getGroupView()方法)像这样,如何更新用户向下滚动的列表视图?

public View getGroupView(final int arg0, final boolean arg1, View arg2, ViewGroup arg3) { 
    //if(arg2==null){ 
     //arg2=act.getLayoutInflater().inflate(R.layout.layout_exlistview_group, null);   
    } 
    //((TextView)arg2.findViewById(R.id.nameText)).setText(item.getItemName()); 

    if(arg0>=getGroupCount()-1){//chech is near for end 
     /*here i run a asynctask to download data and add items to SparseArray of this class.That sparsearray is the source to the adapter to view them in listview*/ 
    } 

    //return arg2; 
} 

那么这是正确的方式来做到这一点,或者有没有什么好办法做到这一点?

+0

这应该有助于http://benjii.me/2010/08/endless-scrolling-listview-in-android/ – Swayam

回答

1

从您使用的事实getGroupView我假设您使用的是ExpandableListView,而不是常规的ListView,应该在您的问题中说明。

无论哪种方式,最好的方法是将OnScrollListener分配到您的列表中,然后在那里进行检查,而不是在getGroupView

我建议你把东西沿着以下到您的onScroll方法的线路:

if (firstVisibleItem + visibleItemCount > (totalItemCount - NUM_BEFORE_LOAD)) { 
    loadMore() 
} 

其中NUM_BEFORE_LOAD根据您的例子是1,但你可以把任何你想使列表的加载速度比触及底部时要快。