【问题标题】:Is there a way to grab a collection of Views with a particular identifier?有没有办法获取具有特定标识符的视图集合?
【发布时间】:2011-09-08 22:46:19
【问题描述】:

我正在使用包含多个 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"...

【问题讨论】:

    标签: jquery android arrays class view


    【解决方案1】:

    有类似问题的回答:findViewById to return array of Views

    如果您想通过数组访问视图,您必须手动遍历膨胀结果或布局子级。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-01-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-02-27
      • 1970-01-01
      相关资源
      最近更新 更多