1

I'm wondering what techniques others have used to detect if a ListView has enough items in it that it is displaying a scroll bar. For instance, initially my ListView is empty but based on user interactions the ListView can begin to had items added to it. I read through a similar question here but was having some trouble getting it to work and am wondering if there are other implementations people have used. I'm not seeing an XML attribute that I can check but maybe I'm missing something.

Thanks for any help on the matter.

Community
  • 1
  • 1
devnulldad
  • 25
  • 5
  • I'm not too sure what you're looking for, but could you be more specific about what you're trying to achieve? Do you want the scrollbar to only appear after a certain number of items? – Brian May 12 '14 at 03:41
  • @Brian, not quite. After enough items had been programmatically added to my ListView causing the scrollbar to display I wanted to show my user a quick Toast. – devnulldad May 13 '14 at 01:55

1 Answers1

0

It is not the perfect solution for your problem, still it gives you some relief.

You can find whether the listview exceeded the screen or not by using scroll listener and one condition inside onscroll method.

  listView.setOnScrollListener(new OnScrollListener() {

                @Override
                public void onScrollStateChanged(AbsListView view, int scrollState) {
                    // TODO Auto-generated method stub

                }

                @Override
                public void onScroll(AbsListView view, int firstVisibleItem,
                        int visibleItemCount, int totalItemCount) {list.getLastVisiblePosition());
                    if ((dataList.size() - 1) > list.getLastVisiblePosition()) {
                        Log.d("learn", "page full");
                    } else
                        Log.d("learn", "page not full");
                }
            });

onScroll method will get called first time when you setup listview without any scroll event.

Sreedhu Madhu
  • 2,480
  • 2
  • 30
  • 40
  • Would this actually work for determining the instant when enough items have been added to a ListView causing it to display a scrollbar? I didn't try the code but it looks more like it would determine that the page isn't full initially but it wouldn't actually note that the page was full until someone interacts with the scrollbar. I'm marking as unanswered for now until I can try it. – devnulldad May 13 '14 at 01:54
  • I was hoping to find out about some XML attribute or method I had missed which would simply tell me whether a ScrollView or ListView was currently displaying a scrollbar or not but it seems like there's a few more steps than that – devnulldad May 13 '14 at 01:55