多语言获取索引

2022-08-24  本文已影响0人  坏小子_嘟嘟
[api引用地址](https://developer.android.com/reference/android/icu/text/AlphabeticIndex)

   Locale locale = getResources().getConfiguration().getLocales().get(0);//获取语言
        AlphabeticIndex<MatchListBean.ListBean> index = new AlphabeticIndex<MatchListBean.ListBean>(locale).addLabels(Locale.ENGLISH);//设置当前语言, 增加更多的语言
        index.setUnderflowLabel("#");
//添加数据
        for (MatchListBean.ListBean bean : matchList) {
            if (TextUtils.isEmpty(bean.getLeague())) {
                index.addRecord("#", bean);
            } else {
                index.addRecord(bean.getLeague(), bean);
            }
        }

        List<FilterGLTimeBean> countryBeans = new ArrayList<>();
//获取已经排序好的数据
        for (AlphabeticIndex.Bucket<MatchListBean.ListBean> bucket : index) {
            if (bucket.size() != 0) {
                for (AlphabeticIndex.Record<MatchListBean.ListBean> item : bucket) {
                    MatchListBean.ListBean matchBean = item.getData();
                    List<MatchListBean.ListBean> listBeans = new ArrayList<>();
                    listBeans.add(matchBean);
                    FilterGLTimeBean countryBean = new FilterGLTimeBean(bucket.getLabel(), matchBean.getLeague(), listBeans, true);
                    if (mFilterInputBean.getSelectType() == 1 && mFilterInputBean.getSelectList().size() > 0) {
                        countryBean.setSelect(mFilterInputBean.getSelectList().contains(countryBean));
                    }
                    if (countryBeans.contains(countryBean)) {
                        for (FilterGLTimeBean bean : countryBeans) {
                            if (TextUtils.equals(bean.getName(), countryBean.getName())) {
                                bean.getMatchList().add(matchBean);
                            }
                        }
                    } else {
                        countryBeans.add(countryBean);
                    }
                }
            }
        }
上一篇下一篇

猜你喜欢

热点阅读