Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Removing All Child Views from View

Tags:

android

viewGroup.removeAllViews()

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

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


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

Try this

RelativeLayout  relativeLayout = findViewById(R.id.realtive_layout_root);
    relativeLayout.removeAllViews();

This code is working for me.