ListView快速滚动条bug

3
我正在开发一个词典应用程序。我有一个启用快速滚动的列表视图和一个实现SectionIndexer的适配器。当我使用中文词典时,比使用西欧语言时有更多的部分,并遇到了一个小问题:
如果我停止快速滚动,并在滚动条可见时开始使用默认滚动,我的“快速滚动滚动条”立即移动到另一个位置(某处在顶部),只有当我接近列表末尾时它才以更快的速度开始移动到我的位置。这种行为有什么原因吗?是否有办法在使用默认滚动时隐藏快速滚动条(但不禁用快速滚动)?

我发现这个 bug 与 http://code.google.com/p/android/issues/detail?id=33293 相似。原因是 getSectionForPosition 和 getPositionForSection 方法的实现有误,但我简单地不明白如何正确实现它们。 - Lingviston
1个回答

0

我想在这里发布一下,希望还不算太晚。

注意:这并不是使用 AlphabetIndexer,我认为使用三个集合来管理列表并不是一个好主意,尽管它很简单,但可以解释概念。

以下是如何使用回调函数的基本示例:

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>();  

当你有一个“位置”数组(预排序)时,这将创建三个哈希映射来跟踪事物,实现非常简单,易于阅读:
 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);
    }  
}   

这里是三个回调函数:

@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();
}

希望对您有所帮助!


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接