ListView fast scrolling error

I am working on a dictionary app. I have a list with fast scrolling support and an adapter that implements SectionIndexer. When I work with a Chinese dictionary I have a lot more sections, then when you work with Western European languages ​​and have a little problem:

if i stop fast scrolling and while the scrollbars are visible, start using the default scrolling of my "fast scroll scroll" to another position (somewhere at the top) and only when i get almost at the end of the list will it start to move to my higher position too speed.

Is there a reason for this behavior? If there is a way to hide the fast scrollbars when using the default scrolling (but without disabling fast scroll)?

+3


source to share


1 answer


thought i would post here hoping it is not too late.

Note. This does not use AlphabetIndexer, and I don't think using three collections to manipulate the list is a good idea, although it just explains the concept simply.

Below is a basic example of using 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 array of "locations" (pre-ordered), this will create three hash maps to keep track of things, a really simple implementation, very 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 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!

0


source







All Articles