在Recyclerview或Listview中添加多个标题.随机

在Recyclerview或Listview中添加多个标题.随机,第1张

概述如何在RecyclerView或listview中添加多个标题或分隔符.随机突出显示在下图中: RecyclerView中基于日期的多个标题 – 演示图像 您可以使用库 SectionedRecyclerViewAdapter来实现它.它具有“部分”的概念,每个部分都可以有自己的标题. 在我看来,您需要按“日期”对呼叫进行分组.所以你可以像这样创建你的Section类: class MySecti 如何在RecyclerVIEw或ListvIEw中添加多个标题或分隔符.随机突出显示在下图中:

RecyclerVIEw中基于日期的多个标题 – 演示图像

解决方法 您可以使用库 SectionedRecyclerViewAdapter来实现它.它具有“部分”的概念,每个部分都可以有自己的标题.

在我看来,您需要按“日期”对呼叫进行分组.所以你可以像这样创建你的Section类:

class MySection extends StatelessSection {    String date;    List<Call> callList;    public MySection(String date,List<Call> callList) {        // call constructor with layout resources for this Section header,footer and items         super(R.layout.section_header,R.layout.section_footer,R.layout.section_item);        this.date = date;        this.callList = callList;    }    @OverrIDe    public int getContentItemsTotal() {        return callList.size(); // number of items of this section    }    @OverrIDe    public RecyclerVIEw.VIEwHolder getItemVIEwHolder(VIEw vIEw) {        // return a custom instance of VIEwHolder for the items of this section        return new MyItemVIEwHolder(vIEw);    }    @OverrIDe    public voID onBindItemVIEwHolder(RecyclerVIEw.VIEwHolder holder,int position) {        MyItemVIEwHolder itemHolder = (MyItemVIEwHolder) holder;        // bind your vIEw here        itemHolder.tvItem.setText(callList.get(position).getContactname());    }    @OverrIDe    public RecyclerVIEw.VIEwHolder getheaderVIEwHolder(VIEw vIEw) {        return new SimpleheaderVIEwHolder(vIEw);    }    @OverrIDe    public voID onBindheaderVIEwHolder(RecyclerVIEw.VIEwHolder holder) {        MyheaderVIEwHolder headerHolder = (MyheaderVIEwHolder) holder;        // bind your header vIEw here        headerHolder.tvItem.setText(date);    }}

然后使用您的章节设置RecyclerVIEw:

// Create an instance of SectionedRecyclerVIEwAdapter SectionedRecyclerVIEwAdapter sectionAdapter = new SectionedRecyclerVIEwAdapter();MySection mySection1 = new MySection("27 Mar,2016",callList1);MySection mySection2 = new MySection("28 Mar,callList2);// Add your SectionssectionAdapter.addSection(mySection1);sectionAdapter.addSection(mySection2);// Set up your RecyclerVIEw with the SectionedRecyclerVIEwAdapterRecyclerVIEw recyclerVIEw = (RecyclerVIEw) findVIEwByID(R.ID.recyclervIEw);recyclerVIEw.setLayoutManager(new linearlayoutmanager(getContext()));recyclerVIEw.setAdapter(sectionAdapter);
总结

以上是内存溢出为你收集整理的在Recyclerview或Listview中添加多个标题.随机全部内容,希望文章能够帮你解决在Recyclerview或Listview中添加多个标题.随机所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/1136933.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-30
下一篇2022-05-30

发表评论

登录后才能评论

评论列表(0条)

    保存