android - ListView快速滚动条bug

标签 android listview adapter fastscroll sectionindexer

我正在研究字典应用程序。我有一个启用了快速滚动的 ListView 和实现 SectionIndexer 的适配器。当我使用中文字典时,我的部分比使用西欧语言时多得多,但有一个小问题:

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.

这种行为有原因吗?在使用默认滚动时(但不禁用快速滚动)是否有任何方法可以隐藏快速滚动条?

最佳答案

我想我会在这里发帖,希望现在还不算太晚。

注意:这不是使用 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>();  

当你有你的“位置”数组(预先订购)时,这将创建三个 HashMap 来跟踪事物,非常简单的实现,非常容易阅读:

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

希望对您有所帮助!

关于android - ListView快速滚动条bug,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14648454/

相关文章:

java - 如何检查设备上是否存在应用程序?

Android:将 View 转换到 View

android - ListView 同一行中的两个可点击项目

android - 如何创建多个上下文菜单?

android - 如何将图像加载到 ListView 适配器中的正确行

android - 即时应用程序和拆分 abi

Android ListView onTouchEvent 并不总是给出 ACTION_DOWN

c++ - Java 的最佳方法,如 C++ 中的适配器事件处理

android - 彩色方 block 的GridView -- Android

android - 使用 react-native 启用电话设置