Skip to content

Android_DataGridView(已停更)

本项目由 Lingber 开发,是一个基于 Android 的表格控件,具有表头、分页、排序、选择等功能,适用于展示结构化数据。

https://github.com/Lingber/Android_DataGridView


🔧 功能特性

  • 支持表头显示列排序单选 / 多选
  • 支持分页功能,便于大数据集展示
  • 支持滑动浏览单双行间隔样式自定义
  • 支持配置选中行样式
  • 自定义表格高度、分隔线宽度等 UI 属性 (github.com, cnblogs.com)

⚙️ 快速上手

📦 添加依赖

在项目 settings.gradle 或根 build.gradle 中添加 JitPack 仓库:

allprojects {
  repositories {
    ...
    maven { url 'https://www.jitpack.io' }
  }
}

在模块 build.gradle 中添加依赖:

implementation 'com.github.Lingber:Android_DataGridView:1.01'
``` :contentReference[oaicite:6]{index=6}

### 📐 布局使用示例

```xml
<com.lingber.mycontrol.datagridview.DataGridView
    android:id="@+id/datagridview"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:show_header="true"
    app:row_height="50"
    app:dividerSize="2" />
``` :contentReference[oaicite:7]{index=7}

### 👥 数据源设置

定义数据对象类,例如:

```java
public class SellerBean {
    private Integer index;
    private String name;
    private Integer age;
    private String sex;
    private String department;
    private String rank;
    private Double sales;
    // 构造器、省略 getter/setter
}

在 Activity/Fragment 中初始化控件并设置数据源:

DataGridView grid = findViewById(R.id.datagridview);
List<SellerBean> data = ...
grid.setDataSource(data);
grid.initDataGridView();
``` :contentReference[oaicite:9]{index=9}

### 🧩 丰富的 API 支持

- `getDataSource()`:获取完整数据源
- `getPageDatas()`:获取当前页面数据
- `getSelectedRowsData()`:获取选中行数据
- `getRowData(row)`:读取指定行
- `updateARow(...)`、`updateAll()`:更新行或全部数据
- 支持监听单元格点击事件
  ```java
  setOnItemCellClickListener((v, row, col) -> { ... });
  setOnItemCellContentClickListener(...);

并可获取单元格视图:getItemCellView(row,col)getItemCellContentView(row,col) (github.com)


✅ 优势与适用场景

  • 零门槛集成:几行 XML + 几行 Java 即可实现表格功能。
  • 开箱即用的功能支持:表头、分页、排序、选择、样式等一应俱全。
  • 适合多场景展示:从表格列表到数据仪表盘均适用。
  • 美观实用:滑动体验流畅、样式灵活配置、交互体验佳。

⚠️ 注意事项与替代方案

  • 已停止更新:最后版本 1.01,于 2021 年发布,后续无维护 (github.com)。
  • 功能有限:不支持如冻结列、合并单元格、高性能滚动、大数据下懒加载等高级功能。
  • 建议替代方案

  • 使用 RecyclerView + GridLayoutManager 或 Jetpack Compose 的 LazyGrid,自定义灵活;

  • 若使用 Web 技术可采用 React Native 社区的 table 组件。

✅ 总结

Android_DataGridView 是一个轻量级、易用的 Android 表格组件,提供了常用功能,适合中小型项目快速集成。但由于长期不更新,功能和兼容性上建议选用更现代的 RecyclerView 或 Compose 实现。


Ref

https://github.com/Lingber/Android_DataGridView https://www.cnblogs.com/Lingber/p/15329102.html https://blog.csdn.net/Ling_ber/article/details/120322087 https://blog.51cto.com/u_16213392/8029407 https://www.jianshu.com/p/039641263aaa https://blog.csdn.net/liquan1434/article/details/124014651 https://android-components.readthedocs.io/en/latest/grid/ https://www.cnblogs.com/cxyzj/p/5026046.html