Removing All Child Views from View
Solution 1:
viewGroup.removeAllViews()
works for any viewGroup. in your case it is GridView.
http://developer.android.com/reference/android/view/ViewGroup.html#removeAllViews()
Solution 2:
You can remove only some types of view in a ViewGroup with this function :
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;
}
}
}
Solution 3:
Try this
RelativeLayout relativeLayout = findViewById(R.id.realtive_layout_root);
relativeLayout.removeAllViews();
This code is working for me.