有没有办法获取具有特定标识符的视图集合?
我正在使用包含许多 TextView 的 LinearLayout。其中一些 TextView 属于一个功能类别,我想以 jQuery-esq 的方式引用它们。我有
<TextView android:id="@+id/text1"...
等等,有text2、3、4……,但这些标识符是唯一的。是否有类似于 CSS 类的东西,因此我可以从代码中通过数组一次引用多个视图?
理想的情况是具有如下所示的内容:
View[] views = getAllViewsofClass( c );
然后在布局 xml 中我会具有类似的内容
<TextView android:id="@+id/text1" class="c"...
I'm working with a LinearLayout that contains a number of TextViews. Some of those TextViews belong to one functional category, and I'd like to refer to them in a jQuery-esq manner. I have
<TextView android:id="@+id/text1"...
and so on, with text2, 3, 4, ..., but these identifiers are unique. Is there something similar to CSS classes, so from code I can then refer to a multitude of Views at once, via an array?
What would be ideal is to have something like the following:
View[] views = getAllViewsofClass( c );
Then in the layout xml I'd have something like
<TextView android:id="@+id/text1" class="c"...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
有类似的问题和答案: findViewById to return array of Views
如果你想要要通过数组访问视图,您必须手动迭代膨胀结果或布局的子项。
There is similar question with answer: findViewById to return array of Views
If you want to access views via array you have to manually iterate through result of inflation or children of layout.