Android: Detect if a ListView has the scrollbar (after setting new data)

Viewed 1413

I have an ArrayAdapter linked to a ListView.

mListView.setAdapter(mArrayAdapter);

Whenever I reset the ArrayList data to the ArrayAdapter:

mArrayAdapter.clear();
mArrayAdapter.addAll(mArrayList);
mArrayAdapter.notifyDataSetChanged()

the ListView gets correctly updated

however, if just after the above three lines, I call my custom method mListView.hasScrollbar() to detect whether the listview has a scrollbar or not, I get a null lastVisibleItem:

public boolean hasScrollbar() {
    View lastVisibleItem = (View) getChildAt(getChildCount() - 1);
    if (lastVisibleItem.getBottom()>=getHeight()) {
        return true;
    }
    return false;
}

does it mean that the listview is still refreshing?

My main question is:
how can I test if the listview has the scrollbar after resetting the adapter with new data?

thank you for any help!

2 Answers
Related