我的布局中有8个Textview现在它们是空白的我想得到那些8个textivews id的数组,以便我可以在以后随机选择15个文本中的15个以后设置文本视图
答案 0 :(得分:0)
试试这个
public View[] getViewArrays(int resid)
{
ViewGroup layout = (ViewGroup) this.findViewById(resid);
View[] views = new View[layout.getChildCount()];
for (int i = 0; i < layout.getChildCount(); i++) {
views[i] = layout.getChildAt(i);
}
return views;
}
public int[] getViewIds(int resid)
{
ViewGroup layout = (ViewGroup) this.findViewById(resid);
int[] ids = new int[layout.getChildCount()];
for (int i = 0; i < layout.getChildCount(); i++) {
ids[i] = layout.getChildAt(i).getId();
}
return ids;
}