find Parent View Holder Item View - Android User Interface

Android examples for User Interface:View Find

Description

find Parent View Holder Item View

Demo Code


import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewParent;

public class Main{
    public static View findParentViewHolderItemView(View v) {
        final ViewParent parent = v.getParent();
        if (parent instanceof RecyclerView) {
            // returns the passed instance if the parent is RecyclerView
            return v;
        } else if (parent instanceof View) {
            // check the parent view recursively
            return findParentViewHolderItemView((View) parent);
        } else {/*  www . j a v  a2s  .com*/
            return null;
        }
    }
}

Related Tutorials