everyone. I want to show the footer like "Loading..." when user reaches bottom of the list. Now I only managed to determine when we are on the last element. Then trouble comes. We need to set up footer before setting adapter, we need to hide it afterwards. Does anyone have solution to this? May be this issue is already discussed, but I haven't found an answer.
Asked
Active
Viewed 4,173 times
2 Answers
4
you can add the Footer before setting the adapter with
listView.addFooterView(yourFooterView, null, true);
*Note that the parameters should suit your objective.
Then you activity could implement OnScrollListener
and on the method onScroll
you can get the last item like this:
public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount){
int lastItem = firstVisibleItem + visibleItemCount;
if(lastItem == totalItemCoun){
// fill your next set of items
}
}
After the new set is filled, the footer will go to the bottom again, so you dont have to hide it. However, if you want to remove it you can use
lv.removeFooterView(yourFooterView);
I hope this helps

raukodraug
- 11,519
- 4
- 35
- 37
-
thanks, but, the point is that I don't need it before user reaches bottom of the list. – Konstantin Milyutin Mar 02 '11 at 20:11
-
1I don't see why not set it before getting to the button, the user won't see it either ways. But, if you really want to do it like that, maybe you can create a "dummy" item in the list when the user reaches the bottom, you can create its own layout, and then treat it as described above. What do you think? – raukodraug Mar 02 '11 at 20:16
-
ok, If I set it at the beginning the user will see "Loading..." always, even if nothing is loaded. it's possible only if I can change the text of the footer, then I can set text later. – Konstantin Milyutin Mar 02 '11 at 20:26
-
hmm, maybe i didnt understand your scenario very well, I thought you had to scroll to reach it, which would make it visible only when they reached it. But yeah, you can set the text later, since the footer is a view, you can access its children and set the text. How does that sound? – raukodraug Mar 02 '11 at 20:33
-
Yes, I have to scroll to reach it. But you proposed to call addFooterView() before setting adapter. So It's visible from the beginning now. How should I solve it? – Konstantin Milyutin Mar 02 '11 at 20:37
-
oh ok, i see, well, you can set the adapter after you get your data, not before, that way the footer wont even exist at the beginning. If this doesnt satify your needs, then try using that "dummy" row that could work as a footer. – raukodraug Mar 02 '11 at 22:16
2
you can, as proposed on this question, call the setFooterView before setting adapter and remove it just after, and then use setFooterView and removeFooterView in onScroll as needed. This works and I have tested it, in aforementioned page there are other solutions proposed as well.

Community
- 1
- 1

Lukasz 'Severiaan' Grela
- 6,078
- 7
- 43
- 79