0
我需要在RelativeLayout裏面找到所有的TextView,對於這個,我使用for(;;)循環,但是面對奇怪的問題,循環並沒有全部刪除視圖。如果佈局有2個孩子,則1個將被刪除,1個將保留。有時候,循環會刪除所有的TextView,但是在下一次使用leave 1的時候。Loop不會從RelativeLayout中刪除所有需要的視圖
這裏是我的代碼:
int viewCount = relativeLayout.getChildCount();
for (int i1=0; i1 < viewCount ; i1++){
if (relativeLayout.getChildAt(i1) instanceof TextView) {
relativeLayout.removeViewAt(i1);
}
}
編輯:
這裏是右環:
while (viewCount != -1){
if (relativeLayout.getChildAt(viewCount) instanceof TextView) {
relativeLayout.removeViewAt(viewCount);
}
viewCount--;
}