在Android 4.4系统的快速滚动的问题 [英] Issues with Fast Scroll in Android 4.4

查看:90
本文介绍了在Android 4.4系统的快速滚动的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写了一个应用程序,其中包含一个支持快速滚动在它的布局一个ListView(即拖动滚动条滑块可让您快速向上或向下滚动列表)。这在所有版本果冻豆(4.1-4.3)的完美。然而,当我更新到奇巧,快速滚动不再起作用,而我的滚动条仅仅是一个正常的滚动条。不过,如果我在转出我的应用程序和背部,出现快速滚动。如何获得快速滚动工作始终在奇巧?我,已经复制并粘贴我的列表视图的适配器code如下:

  //添加部分弹出的快速滚动
类NameListAdapter扩展SimpleAdapter实现SectionIndexer {
    HashMap的<字符串,整数> alphaIndexer;
    私有String []段;
    私人的ArrayList<字符串> sectionList;
    私人列表< HashMap的<字符串,字符串>>数据= NULL;

    公共NameListAdapter(上下文的背景下,名单,其中,HashMap的<字符串,字符串>>的数据,
            INT资源的String []从,INT []键){
        超(背景下,数据,资源,从,到);
        alphaIndexer =新的HashMap<字符串,整数>();
        sectionList =新的ArrayList<字符串>();
        this.data =数据;
        INT大小= data.size();

        的for(int i = 0; I<大小;我++){
            HashMap的<字符串,字符串> myData的=(&HashMap中所述;字符串,字符串&GT)data.get(ⅰ);
            //获取第一个字符
            。串CH = myData.get(姓名)子串(0,1);
            //转换字符大写
            CH = ch.toUpperCase();

            //将第一个字符/索引我们的HashMap
            如果(!alphaIndexer.containsKey(CH)){
                alphaIndexer.put(CH,I);
                sectionList.add(CH);
            }
        }
        部分=新的String [sectionList.size()];
        sectionList.toArray(段);
    }

    @覆盖
    公众诠释getPositionForSection(INT部分){
        如果(节> = sections.length){
            返回getCount将() -  1;
        }

        返回alphaIndexer.get(第[节]);
    }

    @覆盖
    公众诠释getSectionForPosition(INT POS){

        如果(POS> data.size()){
            返回0;
        }

        HashMap的<字符串,字符串> myData的=(HashMap的<字符串,字符串>)data.get(POS);
        。串CH = myData.get(姓名)子串(0,1);
        //转换字符大写
        CH = ch.toUpperCase();

        的for(int i = 0; I< sectionList.size();我++){
            如果(sectionList.get(ⅰ).equals(CH)){
                返回我;
            }
        }
        返回0;

    }

    @覆盖
    公共对象[] getSections(){
        返回段;
    }
}
 

解决方案

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

 如果(Build.VERSION.SDK_INT> = Build.VERSION_ codeS.KITKAT){
    view.setFastScrollAlwaysVisible(真正的);
}
 

这将让你快速卷轴上所有的时间。

I wrote an app which contains a ListView in its layout that supports fast scroll (i.e. dragging the scroll bar slider allows you to quickly scroll up or down the list). This worked perfectly in all version of Jelly Bean (4.1-4.3). However, after I updated to Kit Kat, fast scroll no longer works, and my scroll bar is just a normal scroll bar. However, if I switch out of my app and back in, fast scroll appears. How do I get fast scroll to consistently work in Kit Kat? I;ve copied and pasted my list view adapter code below:

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

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

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

解决方案

Having the same issue here, it's not a good solution, but for now you can do :

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

This will keep your fast scroller on all the time.

这篇关于在Android 4.4系统的快速滚动的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆