Android 4.4中快速滚动的问题

 549696530_c1f5e8 发布于 2023-02-12 11:41

我编写了一个应用程序,其布局中包含一个支持快速滚动的ListView(即拖动滚动条滑块可以让您快速向上或向下滚动列表).这适用于所有版本的Jelly Bean(4.1-4.3).但是,在我更新到Kit Kat后,快速滚动不再有效,我的滚动条只是一个普通的滚动条.但是,如果我退出我的应用程序并重新登录,则会出现快速滚动.如何快速滚动以在Kit Kat中持续工作?我已经复制并粘贴了下面的列表视图适配器代码:

// Adds section popup for fast scroll
class NameListAdapter extends  SimpleAdapter implements SectionIndexer  {
    HashMap alphaIndexer;
    private String[] sections;
    private ArrayList sectionList;
    private List> data = null;

    public NameListAdapter (Context context, List> data, 
            int resource, String[] from, int[] to) {
        super(context, data, resource, from, to);
        alphaIndexer = new HashMap();
        sectionList = new ArrayList();
        this.data = data;
        int size = data.size();

        for (int i = 0; i < size; i++) {
            HashMap myData = (HashMap ) 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 myData = (HashMap ) 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;
    }
}

Talihawk.. 13

这里有同样的问题,这不是一个好的解决方案,但现在你可以这样做:

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
    view.setFastScrollAlwaysVisible(true);
}

这将使您的快速卷轴始终保持开启状态.

撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有