Answer the question
In order to leave comments, you need to log in
Android ListView task: apparently 3 items, scrolled the rest?
Kind time of day to you people...
Actually the task is described in a question. I understand the essence of the solution - I need a custom adapter in which this is implemented. It is possible to get visible elements (first, last, total number of elements, etc. in onScroll), like a simple check (>/= 3) and do setVisibility(View.HIDE/VISIBLE), but for the life of me I can’t to do this, not to find an example in google ...
I've only spent the second month with Android / Java and maybe my problem and not a problem at all. But maybe someone knows how to show an example of how to do this.
Answer the question
In order to leave comments, you need to log in
You just need a scroll listener.
1. Make a thread method that will load\take from the database with the pagination parameter.
2. By default, it loads the first page, let's say 3 elements, parses what is needed there, feeds it to a regular adapter, etc.
3. Attach a listener to it
public class EndlessScrollListener implements OnScrollListener {
private int visibleThreshold = 5;
private int currentPage = 0;
private int previousTotal = 0;
private boolean loading = true;
public EndlessScrollListener() {
}
public EndlessScrollListener(int visibleThreshold) {
this.visibleThreshold = visibleThreshold;
}
@Override
public void onScroll(AbsListView view, int firstVisibleItem,
int visibleItemCount, int totalItemCount) {
if (loading) {
if (totalItemCount > previousTotal) {
loading = false;
previousTotal = totalItemCount;
currentPage++;
}
}
if (!loading && (totalItemCount - visibleItemCount) <= (firstVisibleItem + visibleThreshold)) {
// I load the next page of gigs using a background task,
// but you can call any function here.
new LoadGigsTask().execute(currentPage + 1);
loading = true;
}
}
@Override
public void onScrollStateChanged(AbsListView view, int scrollState) {
}
}
And why not measure the size of one field (list item) and set the size in the ListView to be field_size*3. Then only three will be visible, the rest will scroll. Or is this not suitable?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question