0

I have a GridView layout that makes use of an ArrayAdapter to populate its contents. I want to make use of fast-scrolling and as such have added the following attributed to the layout XML:

android:fastScrollAlwaysVisible="true"        
android:fastScrollStyle="@android:style/Widget.Material.FastScroll"

I am now able to make use of fast scrolling to navigate but would now like to add a material thumb preview as such:

fastscroll thumb preview

From my understanding, I would have to implement the SectionIndexer interface from my ArrayAdapter as so:

class exampleArrayAdapter extends ArrayAdapter<...> implements SectionIndexer

At this point, I have reached a bump and can't figure out how to get the thumb preview and fear I may be doing something wrong. Pointers as to how I can get this working or what I should look up would be appreciated.

kiyui
  • 375
  • 3
  • 14

1 Answers1

1

I have finally had time to look back at this, and the solution turns out to be very trivial! This is what I did:

@Override
public Object[] getSections() {
    ArrayList<String> labels = new ArrayList<>();
    for (LaunchableActivity activity: mActivityInfos) {
        labels.add(activity.getActivityLabel());
    }

    return labels.toArray();
}

@Override
public int getPositionForSection(int i) {
    return i;
}

@Override
public int getSectionForPosition(int i) {
    // We do not need this
    return 0;
}

I had a list of LaunchableActivity and based of that created a sections array to be returned. For my needs, all I required was to implement getPositionForSection and not getSectionForPosition. Your use case may vary.

The source code where I implemented this is available here, specifically on commits:

  • a2c9ddd1c647919afbf24262ac1a7772a08e468c
  • 08802e17f4c75835c28232353fed68964f5d7746
  • 0d73a788c6b92d7b9c05a2871778da42af02afd8
  • f13a59f02690481801bd07ffc593648b8e71d036
kiyui
  • 375
  • 3
  • 14