回答:
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);
}
}
}