美文网首页
多语言获取索引

多语言获取索引

作者: 坏小子_嘟嘟 | 来源:发表于2022-08-24 09:10 被阅读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);
                        }
                    }
                }
            }
    

    相关文章

      网友评论

          本文标题:多语言获取索引

          本文链接:https://www.haomeiwen.com/subject/mddogrtx.html