Removing All Child Views from View

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;
        }
    }
}

viewGroup.removeAllViews()

works for any viewGroup. in your case it is GridView.

http://developer.android.com/reference/android/view/ViewGroup.html#removeAllViews()

Tags:

Android