SectionIndexer与GridView控件Android中 [英] SectionIndexer with GridView in Android

查看:224
本文介绍了SectionIndexer与GridView控件Android中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有可能使用 SectionIndexer 的GridView Android中?快速滚动工作正常,而我使用的扩展 BaseAdapter 自定义适配器。适配器目前正在实施 SectionIndexer ,似乎是相同的网络和堆栈溢出显示的例子。这使我想到,如果它甚至有可能做一个的GridView 和一个自定义的适配器。

解决方案

 静态类YOUR_ADAPTER扩展SimpleCursorAdapter实现SectionIndexer {

私人AlphabetIndexer mIndexer;

 YOUR_ADAPTER(上下文的背景下,AlbumBrowserActivity currentactivity,
            INT布局,光标光标的String []从,INT []键){
        超(背景下,布局,光标,从,到);

        getColumnIndices(光标);
    }

    私人无效getColumnIndices(光标指针){
        如果(光标!= NULL){
            YOUR_COLUMN = cursor.getColumnIndexOrThrow(WHAT_YOU'RE_SORTING);

            如果(mIndexer!= NULL){
                mIndexer.setCursor(光标);
            } 其他 {
                mIndexer =新AlphabetIndexer(光标,YOUR_COLUMN,mResources.getString(
                        R.string.fast_scroll_alphabet));
            }
        }
    }

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

    @覆盖
    公众诠释getPositionForSection(INT部分){
        返回mIndexer.getPositionForSection(部分);
    }

    @覆盖
    公众诠释getSectionForPosition(INT位置){
        返回0;
    }
}
 

fast_scroll_alphabet 字符串

 <字符串名称=fast_scroll_alphabet> \ u0020ABCDEFGHIJKLMNOPQRSTUVWXYZ< /串>
 

这是一个基本的例子,但没有太多的还不止这一点。实施 SectionIndexer 是pretty的简单。

Is it possible to use a SectionIndexer with a GridView in Android? Fast scroll is working fine, and I'm using a custom adapter that extends BaseAdapter. The adapter is currently implementing SectionIndexer and seems to be identical to the examples shown online and on Stack Overflow. This made me think if it's even possible to do with a GridView and a custom adapter.

解决方案

static class YOUR_ADAPTER extends SimpleCursorAdapter implements SectionIndexer {

private AlphabetIndexer mIndexer;

 YOUR_ADAPTER (Context context, AlbumBrowserActivity currentactivity,
            int layout, Cursor cursor, String[] from, int[] to) {
        super(context, layout, cursor, from, to);

        getColumnIndices(cursor);
    } 

    private void getColumnIndices(Cursor cursor) {
        if (cursor != null) {
            YOUR_COLUMN = cursor.getColumnIndexOrThrow(WHAT_YOU'RE_SORTING);

            if (mIndexer != null) {
                mIndexer.setCursor(cursor);
            } else {
                mIndexer = new AlphabetIndexer(cursor, YOUR_COLUMN, mResources.getString(
                        R.string.fast_scroll_alphabet));
            }
        }
    }

    @Override
    public Object[] getSections() {
        return mIndexer.getSections();
    }

    @Override   
    public int getPositionForSection(int section) {
        return mIndexer.getPositionForSection(section);
    }

    @Override
    public int getSectionForPosition(int position) {
        return 0;
    }
}

fast_scroll_alphabet String

<string name="fast_scroll_alphabet">\u0020ABCDEFGHIJKLMNOPQRSTUVWXYZ</string>

That's a basic example, but there's not much more to it than that. Implementing SectionIndexer is pretty simple.

这篇关于SectionIndexer与GridView控件Android中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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