如何获得在活动的每看法? [英] How to get every Views in an Activity?

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

问题描述

有没有办法让每一个观点,就是在我的活动? 我有超过200视图,包括按键,和图像,所以我希望能够通过一个循环来访问它们

例如像

 的(视图V:这一点)
{
     //做一些事情的看法
     //取决于类型(按钮,图像等)
}
 

解决方案
  

有没有办法让每一个观点,即   里面是我的活动?

让你的根查看,它转换为一个的ViewGroup ,呼叫 getChildCount() getChildAt(),以及递归需要。

  

我有超过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 example something like

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?

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

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

That is a rather large number of Views.

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

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