Java tutorial
//package com.java2s; //License from project: Apache License import android.view.View; public class Main { public static <T extends View> T findParentOfClass(View view, Class<T> theClass) { if (theClass.isAssignableFrom(view.getClass())) return (T) view; else if (view.getParent() != null && view.getParent() instanceof View) return findParentOfClass((View) view.getParent(), theClass); else return null; } }