get Activity from ViewParent - Android android.app

Android examples for android.app:Activity Property

Description

get Activity from ViewParent

Demo Code

import android.app.Activity;
import android.view.ViewParent;

public class Main{

    /**//from w w  w. ja  va 2 s . c  o m
     * Return the {@link Activity} of {@link ViewParent}.
     * 
     * @param parent
     * @return
     */
    public final static Activity getActivity(ViewParent parent) {
        if (parent instanceof Activity) {
            return (Activity) parent;
        }
        if (parent.getParent() != null) {
            return getActivity(parent.getParent());
        }
        return null;
    }


}

Related Tutorials