android - 像 Sony Xperia Contacts 一样右边有字母的 ListView,有可能吗?

标签 android android-listview

<分区>

我搜索了一天以找到可以为我执行此操作的示例或库,请参阅下面的截图:

如果您是 Sony Xperia 用户,您完全知道我要的是什么,正如您在图片中看到的那样,您可以触摸字母并将其向左移动。 进一步移动时,字母会更大。

我在stackoverflow上看到了一些问题,但没有一个符合我的要求。 我尝试的就像常规方式一样。

这是 StackOverFlow 上的问题:ListView with alphabe....还有很多我读过的其他链接,我也可以提供。

最佳答案

为此,您需要一个支持自定义 header 的 ListView

如果您不想亲自动手并寻找更简单的解决方案,请试试这个名为 SuperSLIM. 的库

看下面的例子,

enter image description here

您可以查看默认示例应用程序,它演示了自定义 header 的使用,尤其是按字母顺序排列。

https://github.com/TonicArtos/SuperSLiM/tree/early_release_4/example

请参阅按字母顺序实现 header 的演示应用程序中的示例,

public CountryNamesAdapter(Context context, int headerMode) {
        mContext = context;

        final String[] countryNames = context.getResources().getStringArray(R.array.country_names);
        mHeaderDisplay = headerMode;

        mItems = new ArrayList<>();

        //Insert headers into list of items.
        String lastHeader = "";
        int sectionManager = -1;
        int headerCount = 0;
        int sectionFirstPosition = 0;
        for (int i = 0; i < countryNames.length; i++) {
            String header = countryNames[i].substring(0, 1);
            if (!TextUtils.equals(lastHeader, header)) {
                // Insert new header view and update section data.
                sectionManager = (sectionManager + 1) % 2;
                sectionFirstPosition = i + headerCount;
                lastHeader = header;
                headerCount += 1;
                mItems.add(new LineItem(header, true, sectionManager, sectionFirstPosition));
            }
            mItems.add(new LineItem(countryNames[i], false, sectionManager, sectionFirstPosition));
        }
    }

关于android - 像 Sony Xperia Contacts 一样右边有字母的 ListView,有可能吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31835949/

相关文章:

android - 时间戳(firebase)转换错误到日期实用程序

android - 如何编写 ContactsContract 使其在 2.2 中运行并且不会在 1.5 中崩溃?

java - 如何在android studio中根据设备屏幕的大小调整webview的大小

android - 将 simpleAdapter 与 ListView 的图像一起使用

android - 如何使用相对布局垂直对齐列表中的项目?

java - Greenrobot EventBus3 未发布给我的订阅者

android - adb.exe 的问题 - AdbHostServer.cpp :93: Unable to connect to adb daemon on port: 5037

android-listview - 按钮还是列表?

java - 带有 OnScrollListener 的水平 ListView

android - ListView 的自定义适配器导致错误