本文介绍了Android的:清单认为加载数据动态地根据滚动位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要创建列表视图的加载数据动态地根据滚动位置。像Facebook的用户时,滚动到最后它动态地添加更多的行。有没有标准液呢?
I need to create the list view that loads data dynamically based on scroll position. Like in Facebook when user scrolls to the end it dynamically adds more rows. Is there standard solution it?
推荐答案
试试这个:
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;
}
}
}
这篇关于Android的:清单认为加载数据动态地根据滚动位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!