【问题标题】:Update contents of TextView in Android TableLayout更新 Android TableLayout 中 TextView 的内容
【发布时间】:2019-08-14 06:31:03
【问题描述】:

我有一个 7 列 15 行的表格,每个单元格包含一个 TextView。我想知道是否有一种方法可以在不参考其 id 的情况下更新单个 TextView 的内容 - 即能够在表中定位其位置。

我可以使用下面的代码获取每个单元格的现有值,但看不到如何调整它以更改单元格值。

 private View getCellAtPos(TableLayout table, int pos) {
    TableRow row = (TableRow) table.getChildAt(pos /7);
    return row.getChildAt(pos % 7);
}

【问题讨论】:

    标签: android android-layout tablelayout


    【解决方案1】:

    您的函数 getCellAtPos 返回一个视图对象。您只需将其类型转换为 TextView 对象,因为 View 没有 setText() 方法。

        TextView tv=(TextView)getCellAtPos(table,pos);
        tv.setText("abc");
    

    【讨论】:

      猜你喜欢
      • 2015-05-01
      • 1970-01-01
      • 2012-08-28
      • 1970-01-01
      • 2013-06-25
      • 1970-01-01
      • 2012-05-28
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多