gpt4 book ai didi

android - 如何获取 Activity 中的所有 View?

转载 作者:塔克拉玛干 更新时间:2023-11-01 21:52:01 25 4
gpt4 key购买 nike

有没有办法获取 Activity 中的每个 View ?我有 200 多个 View ,包括按钮和图像,所以我希望能够通过循环访问它们

例如类似的东西

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() , 并根据需要递归。

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

这是一个相当大的 Views

关于android - 如何获取 Activity 中的所有 View?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3221135/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com