2

I'm trying to implement a ListView with a FastScroll mechanism which uses time rather than A-Z

Unfortunately I can't seem to find a way into the layout used by the FastScroller index - it seems determined to show a small black square with very large white text

I've looked at the source:

Both of these seem to show the key fast scroll member variables are private, and that the resource id used is fixed:

mOverlayDrawable = res.getDrawable(com.android.internal.R.drawable.menu_submenu_background);

Is there any way to override this? Ideally I'm targeting 2.2. and above.

Stuart
  • 66,722
  • 7
  • 114
  • 165
  • Hmmm how would you even override the `mFastScroller` variable in the `ListView`? Well, without using reflection . – dmon Mar 24 '12 at 13:42
  • Am I allowed to do that on private variables? (sorry for the newbie question but I'm coming from c# on wp7 and there private is strongly enforced - the reflection methods won't let you touch privates) – Stuart Mar 24 '12 at 14:08

1 Answers1

1

You can try with reflection with something like this:

try {
  Field scrollerField = AbsListView.class.getDeclaredField("mFastScroller"); //java.lang.reflect.Field
  scrollerField.setAccessible(true);
  FastScroller instance = scrollerField.get(listViewInstance);

  Field overlayField = instance.getClass().getDeclaredField("mOverlayDrawable");
  overlayField.setAccessible(true);
  overlayField.set(instance, yourValueHere);
} catch (Exception e) {
  Log.d("Error", "Could not get fast scroller");
}

I just typed it out so it might or might not compile straight off the bat, but that's the idea. I didn't check if the fields were called the same in all of the versions, you might have to adjust.

dmon
  • 30,048
  • 8
  • 87
  • 96