码农知识堂 - 1000bd
  •   Python
  •   PHP
  •   JS/TS
  •   JAVA
  •   C/C++
  •   C#
  •   GO
  •   Kotlin
  •   Swift
  • Android RecyclerView BaseSectionQuickAdapter实现分组功能


    详情网站:手把手教你使用BaseSectionQuickAdapter实现分组功能,史上最详细Adapter使用教程_basequickadapter 分组_杨阿程的博客-CSDN博客 

     

    1. //加入二个包
    2. implementation 'com.android.support:recyclerview-v7:26.0.0-beta1'
    3. implementation 'com.github.CymChad:BaseRecyclerViewAdapterHelper:2.9.34'
    4. import android.support.v7.app.AppCompatActivity;
    5. import android.os.Bundle;
    6. import android.support.v7.widget.GridLayoutManager;
    7. import android.support.v7.widget.RecyclerView;
    8. public class MainActivity extends AppCompatActivity {
    9. private final GridLayoutManager manager = new GridLayoutManager(this, 4);
    10. private final SectionAdapter adapter = new SectionAdapter(R.layout.section_item, R.layout.section_item_header, new ArrayList<>());
    11. @Override
    12. protected void onCreate(Bundle savedInstanceState) {
    13. super.onCreate(savedInstanceState);
    14. setContentView(R.layout.activity_main);
    15. RecyclerView mTreeListRecy = findViewById(R.id.mTreeListRecy);
    16. mTreeListRecy.setLayoutManager(manager);
    17. mTreeListRecy.setAdapter((RecyclerView.Adapter) adapter);
    18. List list = new ArrayList<>();
    19. for (int i = 0; i < 3; i++) {
    20. //添加标题内容
    21. list.add(new SectionBean(true, "标题" + i));
    22. //添加数据内容
    23. for (int j = 0; j < 10; j++) {
    24. list.add(new SectionBean(new SectionBean.SectionDataBean("数据" + j)));
    25. }
    26. }
    27. adapter.addData(list);
    28. }
    29. }
    30. "http://schemas.android.com/apk/res/android"
    31. xmlns:app="http://schemas.android.com/apk/res-auto"
    32. xmlns:tools="http://schemas.android.com/tools"
    33. android:layout_width="match_parent"
    34. android:layout_height="match_parent"
    35. tools:context="com.example.recycler_view_list.MainActivity">
    36. android:id="@+id/mTreeListRecy"
    37. android:layout_width="match_parent"
    38. android:layout_height="wrap_content"/>
    39. import com.chad.library.adapter.base.BaseSectionQuickAdapter;
    40. import com.chad.library.adapter.base.BaseViewHolder;
    41. public class SectionAdapter extends BaseSectionQuickAdapter {
    42. /**
    43. * Same as QuickAdapter#QuickAdapter(Context,int) but with
    44. * some initialization data.
    45. *
    46. * @param layoutResId The layout resource id of each item.
    47. * @param sectionHeadResId The section head layout id for each item
    48. * @param data A new list is created out of this one to avoid mutable list
    49. */
    50. public SectionAdapter(int layoutResId, int sectionHeadResId, List data) {
    51. super(layoutResId, sectionHeadResId, data);
    52. }
    53. @Override
    54. protected void convertHead(BaseViewHolder helper, SectionBean item) {
    55. helper.setText(R.id.mSectionItemHeaderText, item.header);
    56. Log.i(TAG + "_Log_", "2023/2/28: item.header=" +item.header);
    57. }
    58. @Override
    59. protected void convert(BaseViewHolder helper, SectionBean item) {
    60. SectionBean.SectionDataBean bean = item.t;
    61. helper.setText(R.id.mSectionItemText, bean.getStr());
    62. }
    63. }

  • 相关阅读:
    Spring AOP如何基于AspectJ XML开发呢?
    YOLOv5的Tricks | 【Trick14】YOLOv5的val.py脚本的解析
    3.16 总线与信号分支线之间应该如何进行连接?OrCAD中使用Bus总线有哪些注意事项?
    CGAL 计算点云平均密度
    29.CF1149C [Tree Generator™](httpswww.luogu.com.cnproblemCF1149C) 区间合并线段树
    根据给定数组,创建形状相同的数组并且采用不同方式填充full_like()
    使用汇编和反汇编引擎写一个x86任意地址hook
    438页19万字农牧业综合服务信息化减灾应急建设方案
    Python学习基础笔记十六——函数嵌套
    JavaScript--循环优化
  • 原文地址:https://blog.csdn.net/yineng7758258/article/details/132908888
  • 最新文章
  • 攻防演习之三天拿下官网站群
    数据安全治理学习——前期安全规划和安全管理体系建设
    企业安全 | 企业内一次钓鱼演练准备过程
    内网渗透测试 | Kerberos协议及其部分攻击手法
    0day的产生 | 不懂代码的"代码审计"
    安装scrcpy-client模块av模块异常,环境问题解决方案
    leetcode hot100【LeetCode 279. 完全平方数】java实现
    OpenWrt下安装Mosquitto
    AnatoMask论文汇总
    【AI日记】24.11.01 LangChain、openai api和github copilot
  • 热门文章
  • 十款代码表白小特效 一个比一个浪漫 赶紧收藏起来吧!!!
    奉劝各位学弟学妹们,该打造你的技术影响力了!
    五年了,我在 CSDN 的两个一百万。
    Java俄罗斯方块,老程序员花了一个周末,连接中学年代!
    面试官都震惊,你这网络基础可以啊!
    你真的会用百度吗?我不信 — 那些不为人知的搜索引擎语法
    心情不好的时候,用 Python 画棵樱花树送给自己吧
    通宵一晚做出来的一款类似CS的第一人称射击游戏Demo!原来做游戏也不是很难,连憨憨学妹都学会了!
    13 万字 C 语言从入门到精通保姆级教程2021 年版
    10行代码集2000张美女图,Python爬虫120例,再上征途
Copyright © 2022 侵权请联系2656653265@qq.com    京ICP备2022015340号-1
正则表达式工具 cron表达式工具 密码生成工具

京公网安备 11010502049817号