查找与标签的所有意见? [英] Find all views with tag?
本文介绍了查找与标签的所有意见?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我希望找到所有有标签气球,例如,然后使用 setVisibility
隐藏它们以指定活动GONE意见
。
I am looking to find all the views in a specified activity that have the tag "balloon" for example then hide them using setVisibility
to GONE
.
有谁知道如何检索与给定的标签视图列表?
Does anyone know how to retrieve a list of views with a given tag?
推荐答案
在这里你去:
private static ArrayList<View> getViewsByTag(ViewGroup root, String tag){
ArrayList<View> views = new ArrayList<View>();
final int childCount = root.getChildCount();
for (int i = 0; i < childCount; i++) {
final View child = root.getChildAt(i);
if (child instanceof ViewGroup) {
views.addAll(getViewsByTag((ViewGroup) child, tag));
}
final Object tagObj = child.getTag();
if (tagObj != null && tagObj.equals(tag)) {
views.add(child);
}
}
return views;
}
我已经回答了在这里:<一href="http://stackoverflow.com/questions/8817377/android-how-to-find-multiple-views-with-common-attribute">Android - 如何找到有共同属性的多个视图
这篇关于查找与标签的所有意见?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文