• 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. }

  • 相关阅读:
    Redis-String特点和操作-20220730
    数据湖(十二):Spark3.1.2与Iceberg0.12.1整合
    前端适配笔记本缩放125%,150%导致页面错乱问题
    2022.08.15 java学习
    C++:关联式容器map的使用
    文心一言 VS 讯飞星火 VS chatgpt (117)-- 算法导论10.3 2题
    Vue实现简易购物车功能
    【数据库查询表结构】
    Nginx的块、变量以及重定向
    JAVA基础(十三)
  • 原文地址:https://blog.csdn.net/yineng7758258/article/details/132908888