• 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"
  • 相关阅读:
    Python基础复习【第二弹】【黑马】
    SLAM中旋转向量(旋转轴/旋转角)、旋转矩阵、四元数、李代数的相互转化(附C++ Eigen库代码实例)
    正点原子嵌入式linux驱动开发——Linux按键输入
    醋氯芬酸小鼠血清白蛋白纳米粒Aceclofenac-MSA|利凡诺大鼠血清白蛋白纳米粒Ethacridine-RSA
    8位端口检测8位独立按键
    抛射体运动在游戏开发中的实践
    【记录】前端如何实现iPhone不上架AppStore,从游览器直接安装测试App
    Spring 注册 Bean 在配置中的定义和使用 Autowired
    script 标签中的 async 和 defer 属性
    windows下通过mingw编译ffmpeg同时集成x264和x265完全指南
  • 原文地址:https://blog.csdn.net/baidu_24743861/article/details/134468355