find Parent View Holder Item View - Android android.view

Android examples for android.view:ViewParent

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 {//from w  w  w  .  j ava2s  .  co m
            return null;
        }
    }

}

Related Tutorials