Android SmartTable根据int状态格式化文字及颜色

java 复制代码
private void initData() {
        List<UserInfo> list = new ArrayList<>();
        list.add(new UserInfo("一年级", "李同学", 6, 1, 120, 1100, 450, 0));
        list.add(new UserInfo("一年级", "张同学", 6, 2, 120, 1100, 450, 1));
        list.add(new UserInfo("一年级", "王同学", 7, 3, 120, 1100, 450, 2));
        list.add(new UserInfo("一年级", "闻同学", 7, 4, 120, 1100, 450, 0));
        list.add(new UserInfo("二年级", "李同学", 6, 5, 120, 1100, 450, 1));
        list.add(new UserInfo("二年级", "李同学", 6, 6, 120, 1100, 450, 2));
        list.add(new UserInfo("二年级", "李同学", 7, 7, 120, 1100, 450, 0));
        list.add(new UserInfo("二年级", "李同学", 7, 8, 120, 1100, 450, 1));
        list.add(new UserInfo("三年级", "李同学", 6, 9, 120, 1100, 450, 2));
        list.add(new UserInfo("三年级", "李同学", 6, 10, 120, 1100, 450, 0));
        list.add(new UserInfo("三年级", "李同学", 7, 11, 120, 1100, 450, 1));
        list.add(new UserInfo("三年级", "李同学", 7, 12, 120, 1100, 450, 2));


        Column cityColumn = new Column("班级", "class");
        cityColumn.setAutoMerge(true);
        Column nameColumn = new Column("姓名", "name");
        Column countColumn = new Column("年龄", "age");
        Column restaurantColumn = new Column("序号", "index");
        Column kaColumn = new Column("身高", "sg");
        Column wholesaleColumn = new Column("住址", "address");
        Column industryColumn = new Column("电话", "phone");
        Column otherColumn = new Column("状态", "state", new IFormat<Integer>() {
            @Override
            public String format(Integer state) {
                String str = "";
                if (state == 0) {
                    str = "未开始";
                } else if (state == 1) {
                     str = "进行中";
                } else if (state == 2) {
                     str = "已完成";
                }
                return str;
            }
        }, new IDrawFormat() {
            @Override
            public int measureWidth(Column column, int position, TableConfig config) {
                return 0;
            }

            @Override
            public int measureHeight(Column column, int position, TableConfig config) {
                return 0;
            }

            @Override
            public void draw(Canvas c, Rect rect, CellInfo cellInfo, TableConfig config) {
                Paint paint = config.getPaint();
                if (cellInfo.value.equals("未开始")) {
                    paint.setColor(ContextCompat.getColor(context, R.color.red));
                } else if (cellInfo.value.equals("进行中")) {
                    paint.setColor(ContextCompat.getColor(context, R.color.gray));
                } else if (cellInfo.value.equals("已完成")) {
                    paint.setColor(ContextCompat.getColor(context, R.color.colorPrimary));
                }
                paint.setStyle(Paint.Style.FILL);
                c.save();
                c.clipRect(rect);
                c.drawText(cellInfo.value, rect.right - 60, rect.bottom - 15, paint);
                c.restore();
            }
        });

        final TableData<UserInfo> tableData = new TableData<>("测试", list, cityColumn,
                nameColumn, countColumn, restaurantColumn, kaColumn, wholesaleColumn, industryColumn, otherColumn);

        table.setTableData(tableData);

    }
复制代码
com.github.huangyanbin:SmartTable:"2.2.0"
相关推荐
这个杀手不太累40 分钟前
Android ProcessLifecycleOwner
android·lifecycle
sukalot2 小时前
windows显示驱动开发-多监视器管理器(三)
windows·驱动开发
SRC_BLUE_172 小时前
NSSCTF - Web | 【第五空间 2021】pklovecloud
android·前端
tq10864 小时前
学习Hilt注解
android
2501_915921434 小时前
iOS 应用代上架流程,多工具组合与使用 开心上架 跨平台自动化上传指南
android·ios·小程序·uni-app·自动化·cocoa·iphone
日日行不惧千万里4 小时前
2025最新仿默往 IM 即时通讯系统源码(PC + Web + iOS + Android)完整版发布!
android·ios
Java技术实践4 小时前
JPA 用 List 入参在 @Query中报错 unexpected AST node: {vector}
数据结构·windows·list
歪歪1004 小时前
React Native开发Android&IOS流程完整指南
android·开发语言·前端·react native·ios·前端框架
雪芽蓝域zzs4 小时前
uniapp 修改android包名
android·uni-app
wangqiaowq4 小时前
ImmutableList.of() 是 Google Guava 库 提供的一个静态工厂方法,用于创建一个不可变的(immutable)列表。
开发语言·windows·python