Check if View is in Root Namespace via reflection - Android User Interface

Android examples for User Interface:View Parent

Description

Check if View is in Root Namespace via reflection

Demo Code


//package com.java2s;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import android.view.View;

public class Main {
    public static boolean view_isRootNamespace(Object o) {
        boolean root = false;
        try {/* w w  w.  j a v a 2  s .  c om*/
            Method[] methods = View.class.getDeclaredMethods();
            Method method = null;
            for (Method m : methods) {
                if ("isRootNamespace".equals(m.getName())) {
                    method = m;
                    method.setAccessible(true);
                    break;
                }
            }
            if (null != method) {
                root = (Boolean) method.invoke(o,
                        new Object[] { (Object) null });
            }
            //      } catch (NoSuchMethodException e) {
            //         // TODO Auto-generated catch block
            //         e.printStackTrace();
        } catch (IllegalArgumentException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (InvocationTargetException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

        return root;
    }
}

Related Tutorials