获取 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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
您是否尝试过使用
getChildCount()
< /a> 和getChildAt(int)
分别是?循环应该相当容易:
Have you tried using
getChildCount()
andgetChildAt(int)
respectively?Should be fairly easy in a loop:
如果您有其他类型的视图
if you have other type view
一段时间以来我一直在寻找同样的东西。对我来说,我正在寻找如何检查表格布局中的视图。我这样做是通过:
I have been looking for the same thing for a while. For me, I was looking to how to check views in my table layout. I did this by:
如果您尝试删除 TableRows,ID 计数器将会减少,因此请使用此循环来删除...否则,如果您不想删除,您可以使用上面的一些循环:D
这会清除所有行!
我认为你的主要问题是,如果你删除所有行都将被新放置的行,那么如果你删除 ID = 3 的行,则 ID = 5 的行现在是 ID = 4
,所以也许你必须重置计数器并迭代再次或者清除所有行后生成新表
If you try to remove TableRows the ID Counter will decrease so pls use this loop for removing ... else if you dont want to remove you can use some of the loops above :D
This clears all rows!
I think your main problem is if you remove rows that all rows will be newly placed so that the row with the ID = 5 is now ID = 4 if you delete the row with ID = 3
so maybe you have to reset the counter and iterate again or you generate the table new after you cleared all rows