动态重新创建表格布局

发布于 2024-09-27 12:56:09 字数 531 浏览 1 评论 0原文

我在 OnCreate() 中创建了一个动态表布局。每次活动恢复时,表行中的数据都会发生变化,因此我想销毁表行并创建新的行。 我怎样才能做到这一点?谢谢!!!

OnCreate 表创建部分如下所示:

    tableLayout tl = new TableLayout(this);

    for (i = 0; i < numberOfVariables; i++) {

        TableRow tr = new TableRow(this);

        CheckBox cb = new CheckBox(this);
        tr.addView(cb);

        TextView dv = new TextView(this);
        tr.addView(dv);

        EditText et = new EditText(this);
        tr.addView(et);

        tl.addView(tr);
    }

    ll.addView(tl);

I have a dynamic table layout created in OnCreate(). Everytime the activity resumes, the data in the table rows can change, so I would like to destroy the table rows and create new ones.
How can I do that? Thanks!!!

Here is what the OnCreate table creation portion looks like:

    tableLayout tl = new TableLayout(this);

    for (i = 0; i < numberOfVariables; i++) {

        TableRow tr = new TableRow(this);

        CheckBox cb = new CheckBox(this);
        tr.addView(cb);

        TextView dv = new TextView(this);
        tr.addView(dv);

        EditText et = new EditText(this);
        tr.addView(et);

        tl.addView(tr);
    }

    ll.addView(tl);

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

写下不归期 2024-10-04 12:56:09

只需使用 tl.removeAllViews();,然后重新创建行。

Just use tl.removeAllViews();, and then recreate the rows.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文