I wrote an app which contains a ListView in its layout that supports fast scroll (i.e. dragging the scroll bar slider allows you to quickly scroll up or down the list). This worked perfectly in all version of Jelly Bean (4.1-4.3). However, after I updated to Kit Kat, fast scroll no longer works, and my scroll bar is just a normal scroll bar. However, if I switch out of my app and back in, fast scroll appears. How do I get fast scroll to consistently work in Kit Kat? I;ve copied and pasted my list view adapter code below:
// Adds section popup for fast scroll
class NameListAdapter extends SimpleAdapter implements SectionIndexer {
HashMap<String, Integer> alphaIndexer;
private String[] sections;
private ArrayList<String> sectionList;
private List<HashMap<String, String>> data = null;
public NameListAdapter (Context context, List<HashMap<String, String>> data,
int resource, String[] from, int[] to) {
super(context, data, resource, from, to);
alphaIndexer = new HashMap<String, Integer>();
sectionList = new ArrayList<String>();
this.data = data;
int size = data.size();
for (int i = 0; i < size; i++) {
HashMap<String, String> myData = (HashMap <String, String>) data.get(i);
// Get first character
String ch = myData.get("name").substring(0, 1);
// Convert character to upper case
ch = ch.toUpperCase();
// Put first char/index into our HashMap
if (!alphaIndexer.containsKey(ch)) {
alphaIndexer.put(ch, i);
sectionList.add(ch);
}
}
sections = new String[sectionList.size()];
sectionList.toArray(sections);
}
@Override
public int getPositionForSection(int section) {
if (section >= sections.length) {
return getCount() - 1;
}
return alphaIndexer.get(sections[section]);
}
@Override
public int getSectionForPosition(int pos) {
if (pos > data.size()) {
return 0;
}
HashMap<String, String> myData = (HashMap <String, String>) data.get(pos);
String ch = myData.get("name").substring(0, 1);
// Convert character to upper case
ch = ch.toUpperCase();
for (int i = 0; i < sectionList.size(); i++) {
if (sectionList.get(i).equals(ch)) {
return i;
}
}
return 0;
}
@Override
public Object[] getSections() {
return sections;
}
}