unbind Drawables from View - Android User Interface

Android examples for User Interface:View Bitmap

Description

unbind Drawables from View

Demo Code


//package com.java2s;
import android.os.Build;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ImageView;

public class Main {
    public static void unbindDrawables(View view) {
        if (null == view) {
            return;
        }// w  w w  .  j a  v  a2s.c  om
        if (view.getBackground() != null) {
            view.getBackground().setCallback(null);
            if (Build.VERSION.SDK_INT >= 16)
                view.setBackground(null);
            else
                view.setBackgroundDrawable(null);
        }
        if (view instanceof ImageView) {
            ImageView imageView = (ImageView) view;

            if (imageView.getDrawable() != null) {
                imageView.getDrawable().setCallback(null);
                imageView.setImageDrawable(null);
            }
        }
        if (view instanceof ViewGroup) {
            for (int i = 0; i < ((ViewGroup) view).getChildCount(); i++) {
                unbindDrawables(((ViewGroup) view).getChildAt(i));
            }
            if (!(view instanceof AdapterView<?>)) {
                ((ViewGroup) view).removeAllViews();
            }
        }
    }
}

Related Tutorials