0
我在我的佈局中有8個Textviews他們現在是空白現在我想要獲得這些8 textivews ID的數組,以便我隨後可以在隨機選擇15個文本之後設置TextView如何從佈局檢索8 Textviews
我在我的佈局中有8個Textviews他們現在是空白現在我想要獲得這些8 textivews ID的數組,以便我隨後可以在隨機選擇15個文本之後設置TextView如何從佈局檢索8 Textviews
試試這個
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;
}