如何获取活动中的所有视图? [英] How to get all Views in an Activity?

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

问题描述

有没有一种方法可以获取我活动中的每个视图? 我有200多个视图,包括按钮和图像,所以我希望能够通过循环访问它们

is there a way to get every view that is inside my activity? I have over 200 views including buttons, and images, so i want to be able to access them by using a loop

例如类似

for (View v : this)
{
     //do something with the views 
     //depending on the types (button, image , etc)
}

推荐答案

有没有一种方法可以获取每个 在我的活动中吗?

is there a way to get every view that is inside my activity?

获取您的根View,将其转换为ViewGroup,调用getChildCount()getChildAt(),然后根据需要进行递归.

Get your root View, cast it to a ViewGroup, call getChildCount() and getChildAt(), and recurse as needed.

我有200多次观看,包括 按钮和图片,所以我想成为 能够通过循环访问它们

I have over 200 views including buttons, and images, so i want to be able to access them by using a loop

这是大量的Views.

这篇关于如何获取活动中的所有视图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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