remove View from Parent - Android User Interface

Android examples for User Interface:View Parent

Description

remove View from Parent

Demo Code


//package com.java2s;

import android.view.View;
import android.view.ViewGroup;

public class Main {
    public static void removeView(View view) {
        if (view != null) {
            ViewGroup parent = getParent(view);
            if (parent != null) {
                parent.removeView(view);
            }/*from   w w  w.  jav  a 2s  .c  om*/
        }
    }

    public static ViewGroup getParent(View view) {
        return (ViewGroup) view.getParent();
    }
}

Related Tutorials