有没有办法获取具有特定标识符的视图集合?

发布于 2024-12-03 13:20:11 字数 425 浏览 1 评论 0原文

我正在使用包含许多 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

南城旧梦 2024-12-10 13:20:11

有类似的问题和答案: 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文