3

I'm working on dictionary application. I have a listview with fast scroll enabled and adapter which implements SectionIndexer. When I'm working with chinese dictionary I have much more sections then when working with west-european languages and have a small issue:

if I stop fast scrolling and while scroll bars are visible begin using default scrolling my "fast scroll scroller" immideatly moves to another position (somewhere at the top) and only when I'll get almost to the end of the list it'll start moving to my position too with much greater speed.

Is there a reason for such behaviour? If there any way to hide fast scroll bars when using default scrolling (but without disabling the fast scroll)?

Lingviston
  • 5,479
  • 5
  • 35
  • 67
  • I found that this bug is similar to http://code.google.com/p/android/issues/detail?id=33293 THe reason is wrong implementation of getSectionForPosition&getPositionForSection methods, but I simply don't understand how to implement htem right – Lingviston Feb 01 '13 at 15:17

1 Answers1

0

thought I'd post here in the hopes that it's not too late.

Note: This is not using an AlphabetIndexer, and I don't think using three collections to manage a list is a good idea, though it is simple, and explains the concept.

Below is a basic example of how to use the callbacks:

public LinkedHashMap<Integer,String> sectionList = new LinkedHashMap<Integer,String>();
public HashMap<Integer,Integer> sectionPositions = new HashMap<Integer, Integer>();
public HashMap<Integer,Integer> positionsForSection = new HashMap<Integer, Integer>();  

When you have your "locations" array (pre-ordered), this will create three hashmaps to track things, really simple implementation, really easy to read :

 if( locations != null && locations.size() > 0 ) {
    //Iterate through the contacts, take the first letter, uppercase it, and use that as a key to reference the alphabetised list constructed above. 
    for( int i = 0; i < locations.size(); i++ ) {
        String startchar =locations.get(i).getStartCharacterForAlphabet();

        if( startchar != null ) {
            if( sectionList.containsValue(startchar) == false ) {
                sectionList.put(Integer.valueOf(i),startchar);
                positionsForSection.put(Integer.valueOf(sectionList.size() - 1), Integer.valueOf(i));
            }
        }

        sectionPositions.put(Integer.valueOf(i), sectionList.size() - 1);
    }  
}   

And here are the three callbacks:

@Override
public int getPositionForSection(int section) {
    return positionsForSection.get(Integer.valueOf(section)).intValue();
}

@Override
public MyLocation getItem(int position) {
    if( locations.size() > position ) {
        return locations.get(position);
    }

    return null;
}

@Override
public int getSectionForPosition(int position) {
    return sectionPositions.get(Integer.valueOf(position)).intValue();
}

Hope it helps!

user352891
  • 1,181
  • 1
  • 8
  • 14