'Android Listview code for enabling Fast Scroll in android framework source code

In android setFastScrollEnabled(true); is used for making ListView fast scroll.

This fast scroll does not work when there are less items in ListView. I read it somewhere that fast scroll in android works only when listview total height is 4 times or more than listview visible height. I have spent hours trying to find it in framework source code, but I am not able to find it.

Can someone point me to place in android framework source code where this condition to disable fast scroll when there are less items in ListView.



Solution 1:[1]

You can try setting the attribute

android:fastScrollAlwaysVisible="true"

in your listview xml

Solution 2:[2]

Trying to adapt the answer from Micha? Z., I finally ended up doing this :

listView.addOnLayoutChangeListener { _, _, _, _, _, _, _, _, _ ->
    val numberOfPages: Int = listView.count / listView.visibleItemsCount
    listView.isFastScrollAlwaysVisible = numberOfPages > THRESHOLD
}

It works just fine for me

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 sutoL
Solution 2 DJ256