Enabling fast scrolling

Locating a specific item in a large list is fairly difficult, so we should provide a means to help the user get there quickly.

How to do it...

In order to help the user navigate through large lists, Android provides a few means to skip large sections of data. One of these aids is Fast Scroll, or simply, using a scroll thumb.

  • In order to enable the thumb, we set the FastScrollEnabled property:
    listView.FastScrollEnabled = true;
  • Alternatively, if we are using the layout resources, we can set the FastScrollEnabled property as follows:
    android:fastScrollEnabled="true"
  • If we are targeting Android versions 3.0 and later, and want the thumb to always be visible, we can use the FastScrollAlwaysVisible property:
    listView.FastScrollAlwaysVisible = true;

How it works...

Paging through large data collections does not provide a great user experience. Android provides a few means to make the process of skipping over large sections of data easier without the user having to fling the list repeatedly. The simplest way is to enable Fast Scroll, which provides a scroll thumb that can be dragged, thus making it possible to scroll through the list very rapidly.

Tip

Paging through large data collections is not very user-friendly, and there should be a means for the user to jump closer to the desired position.

The thumb is initially disabled, but we can enable it by setting the FastScrollEnabled property to true. Once enabled, the thumb will appear if the list is large enough, usually if the total number of items is four times the number that can fit on the screen.

We can also enable fast scroll from the layout resources. To do this, we set the android:fastScrollEnabled attribute to true. This does exactly the same thing as the FastScrollEnabled property, but we can keep all our view code inside the layout resource.

If we enable fast scroll, the thumb will only appear if the user is actually scrolling through the list. In order to ensure that the thumb is always visible, even when not scrolling, we set the FastScrollAlwaysVisible property to true.

Even though the scroll thumb is very simple, it is a quick means of improving the user experience when we have large lists.

There's more...

When using the thumb, it is very difficult to see where in the list we are, so we can make use of section indexes. This is a small popup that appears as we scroll, displaying an index, such as the first letter of the items. The section index and the thumb make navigating through lists much easier, as the user can skip to a section by dragging the thumb to the desired section.

See also

  • The Optimizing the ListView recipe
  • The Using section indexes recipe
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset