In an android application, I have a linear layout with vertical orientation. This layout contains 2 childs(listview and a textview). The problem is the layout has to show the textview only when the listview has finished scrolling. Plz help me to design the layout?
Asked
Active
Viewed 90 times
1
-
2possible duplicate of [How to add a Footer View (TextView) to the end of a ListView?](http://stackoverflow.com/questions/22388247/how-to-add-a-footer-view-textview-to-the-end-of-a-listview) – madteapot Jul 14 '14 at 18:51
-
possible duplicate of [How can I put a ListView into a ScrollView without it collapsing?](http://stackoverflow.com/questions/3495890/how-can-i-put-a-listview-into-a-scrollview-without-it-collapsing) – njzk2 Jul 14 '14 at 18:56
-
Actually @Setu's duplicate is better suited than mine. – njzk2 Jul 14 '14 at 18:57
1 Answers
2
All you need to know is when the listview is at the bottom or showing the last item, then make your textview visible, this code does the trick:
yourListView.setOnScrollListener(this);//The class must implement onscrolllistener
@Override
public void onScroll(AbsListView lw, final int firstVisibleItem,
final int visibleItemCount, final int totalItemCount) {
switch(lw.getId()) {
case android.R.id.list:
// Make your calculation stuff here. You have all your
// needed info from the parameters of this function.
// Sample calculation to determine if the last
// item is fully visible.
final int lastItem = firstVisibleItem + visibleItemCount;
if(lastItem >= totalItemCount) {
if(preLast!=lastItem){ //to avoid multiple calls for last item
Log.d("Last", "Last");
preLast = lastItem;
//Make your text view visible
}
}
}
}
Is also important to mention that "You Should not have a listview within a ScrollView.", it goes against the Android Design Guidelines and chances are that you are doing something terribly wrong if you go for that approach.
Hope it Helps!
Regards!

Martin Cazares
- 13,637
- 10
- 47
- 54
-
1Thanks Martin. Your solution worked for me. I also took your suggestion and changed my implementation of having a listview inside a scrollview. – Umesh Isran Jul 30 '14 at 09:25