没能获得快速滚动的ExpandableListView工作 [英] Not able to get fast scrolling working on ExpandableListView

查看:118
本文介绍了没能获得快速滚动的ExpandableListView工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我似乎无法得到快速滚动我的 ExpandableListView 工作。更重要的是,我在我的适配器实现的 SectionIndexer 方法从来没有真正打来电话,我已经通过断点验证了这一点。

I can't seem to get fast scrolling working with my ExpandableListView. What's more is that the SectionIndexer methods I have implemented in my adapter are never actually called and I have verified this via breakpoints.

下面是我的活动:

private void onCreate(Bundle a) {
     ...
     setContentView(R.layout.mylayout);
     ...
     setListAdapter(myAdapter);
     getExpandableListView().setFastScrollEnabled(true);
}

下面是我的布局:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">

    <ExpandableListView android:id="@+id/android:list"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:fastScrollEnabled="true"/>

    <TextView android:id="@+id/android:empty"
            android:text="EMPTY! DOOM!"
            android:layout_width="match_parent"
            android:layout_height="match_parent"/>
</LinearLayout>

下面是我的适配器,它的工作原理是这样的:

Here's my adapter, which works by the way:

public class Adapter extends AbstractExpandableListAdapter<TTD, TTL>
        implements SectionIndexer {

    public static class TTDHolder {
        TextView title;
    }

    public static class TTLHolder {
        TextView title;
        ImageView icon;
    }

    private final Pattern alphaMatch = Pattern.compile("^[a-zA-Z]$");

    private final Pattern numberMatch = Pattern.compile("^\\d$");

    private LayoutInflater inflater;

    public Adapter(Context context, int groupClosedView, int groupExpandedView, int childView,
            List<Entry<TTD, List<TTL>>> objects) {
        super(context, groupClosedView, groupExpandedView, childView, objects);
        this.inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    }

    public View getGroupView(int groupPosition, boolean isExpanded,
            View convertView, ViewGroup parent) {
        TTDHolder holder;

        if (convertView != null) {
            holder = (TTDHolder)convertView.getTag();
        } else {
            convertView = inflater.inflate(R.layout.item, parent, false);

            holder = new TTDHolder();
            holder.title = (TextView) convertView.findViewById(R.id.item_title);

            convertView.setTag(holder);
        }

        holder.title.setText(this.getObjects().get(groupPosition).getKey().getName());

        return convertView;
    }

    public View getChildView(int groupPosition, int childPosition,
            boolean isLastChild, View convertView, ViewGroup parent) {
        TTLHolder holder;

        if (convertView != null) {
            holder = (TTLHolder) convertView.getTag();
        } else {
            convertView = inflater.inflate(R.layout.item, parent, false);

            holder = new TTLHolder();
            holder.title = (TextView) convertView.findViewById(R.id.item_title);
            holder.icon = (ImageView) convertView.findViewById(R.id.item_icon);

            convertView.setTag(holder);
        }

        holder.title.setText(this.getObjects().get(groupPosition).getValue()
                .get(childPosition).getName());

        return convertView;
    }

    public Object[] getSections() {
        return "*1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ".split("");
    }

    public int getPositionForSection(int section) {
        for (Entry<TTD, List<TTL>> entry : this.getObjects()) {
            if (entry.getKey().getName().substring(0, 1) == getSections()[section])
                return this.getObjects().indexOf(entry);
        }

        return 0;
    }

    public int getSectionForPosition(int position) {
        List<Object> sections = Arrays.asList(getSections());
        return sections.indexOf(this.getObjects().get(position).getKey().getName().substring(0, 1).toUpperCase());
    }
}

然而,当我滚动,我从来没有看到快速滚动显示出来的,也不是在 SectionIndexer 有史以来的方法实际调用。

However, when I scroll, I never see the fast scroller show up, nor are the SectionIndexer methods ever actually called.

推荐答案

事实证明,你需要在你的适配器项目的最低数量,以便快速视图滚动显示出来。

As it turns out, you need to have a minimum number of items in your adapter in order for the fast-view scroller to show up.

这篇关于没能获得快速滚动的ExpandableListView工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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