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.
Yes ofcourse, here is the link:
http://grepcode.com/file/repository.grepcode.com/java/ext/com.google.android/android/1.5_r4/android/widget/FastScroller.java
This is a condidion between lines 224-227. And for setting how many pages it will be needed to show fast scroll, there is a constant:
private static int MIN_PAGES = 4;
And about disabling it... It's a private field so there is no simply way to do it. You can try use reflections or create custom FastScroller based on original. But i think the simpliest way is to check like in this condidion in Android code:
//pseudocode
int numberOfPages = listView.itemsCount / listView.visibleItemsCount;
if(numberOfPages > yourValue)
listView.setFastScrollEnabled(true);
else
listView.setFastScrollEnabled(false);
But it may only work if yourValue
will be greater than 4. If you want to do it for less values then you need to use reflection or create custom class.
EDIT:
For newest version there is the link: http://grepcode.com/file/repository.grepcode.com/java/ext/com.google.android/android/4.1.1_r1/android/widget/FastScroller.java/
And lines are 444-447 :)
And for reflections I would try something like this:
try {
Field scrollerField = AbsListView.class.getDeclaredField("mFastScroller"); //java.lang.reflect.Field
scrollerField.setAccessible(true);
FastScroller instance = scrollerField.get(listViewInstance);
Field minPagesField = instance.getClass().getDeclaredField("MIN_PAGES");
minPagesField.setAccessible(true);
minPagesField.set(instance, yourValue);
} catch (Exception e) {
Log.d("Error", "Could not get fast scroller");
}
It's not tested so i don't know if it really works.
You can try setting the attribute
android:fastScrollAlwaysVisible="true"
in your listview xml
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With