How to use fast scroll in android?
Asked Answered
U

7

48

I have a list of events which are seperated by month and year (Jun 2010, Jul 2010 etc.)

I want to enable fast scrolling because the list is really long.

How do I enable fast scroll on ListViews in Android?

Untinged answered 21/2, 2012 at 9:13 Comment(0)
E
98

In the onCreate method of the ListActivity use setFastScrollEnabled:

getListView().setFastScrollEnabled(true);
Ewell answered 21/2, 2012 at 9:26 Comment(8)
And note: it will be shown only if listview total height is 4x or more bigger than listview's visible height.Honorine
@mice : Is any documentation regarding your comment?Forte
Probably not documented, the condition is found in source code.Honorine
@mice can you point to place in framework code where this condition is there.Maxma
FastScroller.MIN_PAGES: grepcode.com/file/repository.grepcode.com/java/ext/…Honorine
What about android:fastScrollAlwaysVisible="true"?Canzonet
@maurice How would you enable fast scrolling for a FragmentActivity containing a list fragment?Podvin
Here is how it works for fragments.Podvin
P
67

Use android:fastScrollEnabled in your xml:

<ListView
    android:id="@+id/listview_files"
    ...
    android:fastScrollEnabled="true" >
</ListView>
Putnem answered 30/3, 2012 at 1:7 Comment(0)
D
6

Try the following

 <?xml version="1.0" encoding="utf-8"?>
    <resources>

    <style name="listviewfastscrollstyle" parent="android:Theme">
        <item name="android:fastScrollTrackDrawable">@drawable/listselector</item>
        <item name="android:fastScrollThumbDrawable">@drawable/listselector</item>
    </style>

</resources>

In your Manifest set the style like this:

<application android:icon="@drawable/icon" android:label="@string/app_name" android:theme="@style/CustomTheme">

this is the listview

 <ExpandableListView
        android:id="@android:id/list1"
        android:layout_width="match_parent"
        android:layout_height="0dip"
        android:layout_weight="1"
        android:drawSelectorOnTop="false"
        android:fastScrollAlwaysVisible="true"
        android:fastScrollEnabled="true"
         />
Dhiman answered 15/5, 2013 at 10:46 Comment(1)
Okay can i do a fast scroll by date, i mean while performing fast scroll can i display the date of the record like one in call historyUntinged
C
4

If you want to be able to customize your Fast-scroller, like choosing your own scroller image to appear, I recommend using this source:

https://github.com/nolanlawson/CustomFastScrollViewDemo/

Basically, your listview adapter will have to implement a sectionindexer. This section indexer can be very stripped if you don't want to complicate things and provide simple fastscrolling though the entire length of the list.

The direct source for the fastscroller is here:

https://github.com/nolanlawson/CustomFastScrollViewDemo/blob/master/src/com/nolanlawson/customfastscrollviewdemo/CustomFastScrollView.java

Place this view around your listview (nest your listview inside this view in your xml layout file) and set android:fastScrollEnabled="true" on your listview.

You might also want to check out a previous answer: Fast Scroll display problem with ListAdapter and SectionIndexer

Curtal answered 2/4, 2012 at 21:25 Comment(0)
C
1

I wanted to do something similar to what you wanted to achieve. I bumped into this post. It is a great way to implement fast scrolling without using the standard Android AlphabetIndexer, which requires a Cursor you might not always have.

Basically, you would have to implement the SectionIndexer interface in your adapter. In your case, instead of the current letter, you would show the current period as you scroll.

Culture answered 8/7, 2013 at 22:6 Comment(0)
S
1

Within Layout File :

android:fastScrollEnabled="true"

You Can programmatically Enable Fast scroll bar:

getListView().setFastScrollEnabled(true);

Sf answered 25/5, 2017 at 8:22 Comment(0)
T
0

Either define fastScrollEnabled in your xml or set it at run-time when needed.

1)  <ListView
        ...
        android:fastScrollEnabled="true" />

2) mListView.setFastScrollEnabled(true);
Tomboy answered 18/6, 2015 at 18:3 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.