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


    1. private void initData() {
    2. List list = new ArrayList<>();
    3. list.add(new UserInfo("一年级", "李同学", 6, 1, 120, 1100, 450, 0));
    4. list.add(new UserInfo("一年级", "张同学", 6, 2, 120, 1100, 450, 1));
    5. list.add(new UserInfo("一年级", "王同学", 7, 3, 120, 1100, 450, 2));
    6. list.add(new UserInfo("一年级", "闻同学", 7, 4, 120, 1100, 450, 0));
    7. list.add(new UserInfo("二年级", "李同学", 6, 5, 120, 1100, 450, 1));
    8. list.add(new UserInfo("二年级", "李同学", 6, 6, 120, 1100, 450, 2));
    9. list.add(new UserInfo("二年级", "李同学", 7, 7, 120, 1100, 450, 0));
    10. list.add(new UserInfo("二年级", "李同学", 7, 8, 120, 1100, 450, 1));
    11. list.add(new UserInfo("三年级", "李同学", 6, 9, 120, 1100, 450, 2));
    12. list.add(new UserInfo("三年级", "李同学", 6, 10, 120, 1100, 450, 0));
    13. list.add(new UserInfo("三年级", "李同学", 7, 11, 120, 1100, 450, 1));
    14. list.add(new UserInfo("三年级", "李同学", 7, 12, 120, 1100, 450, 2));
    15. Column cityColumn = new Column("班级", "class");
    16. cityColumn.setAutoMerge(true);
    17. Column nameColumn = new Column("姓名", "name");
    18. Column countColumn = new Column("年龄", "age");
    19. Column restaurantColumn = new Column("序号", "index");
    20. Column kaColumn = new Column("身高", "sg");
    21. Column wholesaleColumn = new Column("住址", "address");
    22. Column industryColumn = new Column("电话", "phone");
    23. Column otherColumn = new Column("状态", "state", new IFormat() {
    24. @Override
    25. public String format(Integer state) {
    26. String str = "";
    27. if (state == 0) {
    28. str = "未开始";
    29. } else if (state == 1) {
    30. str = "进行中";
    31. } else if (state == 2) {
    32. str = "已完成";
    33. }
    34. return str;
    35. }
    36. }, new IDrawFormat() {
    37. @Override
    38. public int measureWidth(Column column, int position, TableConfig config) {
    39. return 0;
    40. }
    41. @Override
    42. public int measureHeight(Column column, int position, TableConfig config) {
    43. return 0;
    44. }
    45. @Override
    46. public void draw(Canvas c, Rect rect, CellInfo cellInfo, TableConfig config) {
    47. Paint paint = config.getPaint();
    48. if (cellInfo.value.equals("未开始")) {
    49. paint.setColor(ContextCompat.getColor(context, R.color.red));
    50. } else if (cellInfo.value.equals("进行中")) {
    51. paint.setColor(ContextCompat.getColor(context, R.color.gray));
    52. } else if (cellInfo.value.equals("已完成")) {
    53. paint.setColor(ContextCompat.getColor(context, R.color.colorPrimary));
    54. }
    55. paint.setStyle(Paint.Style.FILL);
    56. c.save();
    57. c.clipRect(rect);
    58. c.drawText(cellInfo.value, rect.right - 60, rect.bottom - 15, paint);
    59. c.restore();
    60. }
    61. });
    62. final TableData tableData = new TableData<>("测试", list, cityColumn,
    63. nameColumn, countColumn, restaurantColumn, kaColumn, wholesaleColumn, industryColumn, otherColumn);
    64. table.setTableData(tableData);
    65. }

     

    com.github.huangyanbin:SmartTable:"2.2.0"
  • 相关阅读:
    分享43个职场必备excel函数!(内含详细案例解析及教程参考)
    单调栈题目:接雨水
    树莓派4b搭载Centos7系统安装docker
    PAT 1033 To Fill or Not to Fill
    抖音SEO源码
    什么是Lua模块?你会如何使用NGINX的Lua模块来定制请求处理流程?
    第3章业务功能开发(修改市场活动备注)
    Redis-压缩列表
    基于YOLOV8模型和CCPD数据集的车牌目标检测系统(PyTorch+Pyside6+YOLOv8模型)
    【华为上机真题 2022】取近似值
  • 原文地址:https://blog.csdn.net/baidu_24743861/article/details/134468355