Android: List View That Loads Data Dynamically Based On Scroll Position
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 1:
TRY this ::
publicclassTestextendsListActivityimplementsOnScrollListener {
Aleph0adapter=newAleph0();
protectedvoidonCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setListAdapter(adapter);
getListView().setOnScrollListener(this);
}
publicvoidonScroll(AbsListView view,
int firstVisible, int visibleCount, int totalCount) {
booleanloadMore=/* maybe add a padding */
firstVisible + visibleCount >= totalCount;
if(loadMore) {
adapter.count += visibleCount; // or any other amount
adapter.notifyDataSetChanged();
}
}
publicvoidonScrollStateChanged(AbsListView v, int s) { }
classAleph0extendsBaseAdapter {
intcount=40; /* starting amount */publicintgetCount() { return count; }
public Object getItem(int pos) { return pos; }
publiclonggetItemId(int pos) { return pos; }
public View getView(int pos, View v, ViewGroup p) {
TextViewview=newTextView(Test.this);
view.setText("entry " + pos);
return view;
}
}
}
Solution 2:
This is the default behavior for listView. It loads views in items only when items are visible.
Post a Comment for "Android: List View That Loads Data Dynamically Based On Scroll Position"