【问题标题】:ListView with Alphabets in the right like Sony Xperia Contacts, is it possible? [closed]像 Sony Xperia Contacts 一样右边有字母的 ListView,有可能吗? [关闭]
【发布时间】:2015-08-05 14:53:58
【问题描述】:

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

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

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

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

【问题讨论】:

  • 是的,这是可能的。
  • @JaredBurrows:我现在有可能,可以告诉我怎么做吗?或者你能帮帮我吗?

标签: android android-listview


【解决方案1】:

为此,您需要具有自定义标头支持的 ListView

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

请看下面的例子,

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

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

参见演示应用中按字母顺序实现标头的示例,

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));
        }
    }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-10-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多