在TableLayout中获取所有TableRow [英] Get all TableRow's in a TableLayout

查看:84
本文介绍了在TableLayout中获取所有TableRow的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在寻找有关如何在TableLayout中获取所有TableRow的时间.我已经知道如何动态添加和删除行,但是我需要遍历所有行并有选择地删除其中一些.

I've been looking for hours on how to get all TableRow's in a TableLayout. I already know how to add and delete rows dynamically, but I need to loop over all the rows and selectively delete some of them.

我想我可以解决这个问题,但是我正努力避免在我的应用程序中出现粗暴的黑客入侵.

I think I can come up with a work around, but I'm trying to avoid crude hacks in my app.

推荐答案

您是否尝试过使用 getChildCount() 分别是 getChildAt(int) ?

Have you tried using getChildCount() and getChildAt(int) respectively?

在循环中应该很简单:

for(int i = 0, j = table.getChildCount(); i < j; i++) {
    View view = table.getChildAt(i);
    if (view instanceof TableRow) {
        // then, you can remove the the row you want...
        // for instance...
        TableRow row = (TableRow) view;
        if( something you want to check ) {
            table.removeViewAt(i);
            // or...
            table.removeView(row);
        }
    }
}

这篇关于在TableLayout中获取所有TableRow的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆