답변:
viewGroup.removeAllViews()
모든 viewGroup에서 작동합니다. 귀하의 경우에는 GridView입니다.
http://developer.android.com/reference/android/view/ViewGroup.html#removeAllViews ()
ViewGroup?
다음 함수 를 사용하여 ViewGroup 에서 일부 유형의보기 만 제거 할 수 있습니다 .
private void clearImageView(ViewGroup v) {
boolean doBreak = false;
while (!doBreak) {
int childCount = v.getChildCount();
int i;
for(i=0; i<childCount; i++) {
View currentChild = v.getChildAt(i);
// Change ImageView with your desired type view
if (currentChild instanceof ImageView) {
v.removeView(currentChild);
break;
}
}
if (i == childCount) {
doBreak = true;
}
}
}
이 시도
void removeAllChildViews(ViewGroup viewGroup) {
for (int i = 0; i < viewGroup.getChildCount(); i++) {
View child = viewGroup.getChildAt(i);
if (child instanceof ViewGroup) {
if (child instanceof AdapterView) {
viewGroup.removeView(child);
return;
}
removeAllChildViews(((ViewGroup) child));
} else {
viewGroup.removeView(child);
}
}
}