How to implement viewpager in recyclerview
<p>I want to create <code>ViewPager</code> (holder) in <code>RecyclerView</code> when I create it and scroll view pager some row then I scroll <code>RecyclerView</code>and some element that reuse component.</p>

<h2>My Code:</h2>

<p><strong>MainActivity</strong></p>

<pre><code>public class MainActivity extends AppCompatActivity {
    private RecyclerView rcv;
    private LinearLayoutManager llom;
    private MainActivityAdapter adapter;
    private List&lt;String&gt; list1 = new ArrayList&lt;&gt;();
    private List&lt;String&gt; list2 = new ArrayList&lt;&gt;();
    private List&lt;String&gt; list3 = new ArrayList&lt;&gt;();
    private List&lt;String&gt; list4 = new ArrayList&lt;&gt;();
    private List&lt;String&gt; list5 = new ArrayList&lt;&gt;();
    private List&lt;String&gt; list6 = new ArrayList&lt;&gt;();
    private List&lt;String&gt; list7 = new ArrayList&lt;&gt;();
    private List&lt;String&gt; list8 = new ArrayList&lt;&gt;();
    private List&lt;String&gt; list9 = new ArrayList&lt;&gt;();
    private List&lt;String&gt; list10 = new ArrayList&lt;&gt;();
    private HashMap&lt;Integer, List&lt;String&gt;&gt; hashMap = new HashMap&lt;&gt;();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        list1.add("1");
        list1.add("2");
        list1.add("3");
        list1.add("4");
        list1.add("5");

        list2.add("1");
        list2.add("2");
        list2.add("3");
        list2.add("4");
        list2.add("5");

        list3.add("1");
        list3.add("2");
        list3.add("3");
        list3.add("4");
        list3.add("5");

        list4.add("1");
        list4.add("2");
        list4.add("3");
        list4.add("4");
        list4.add("5");

        list5.add("1");
        list5.add("2");
        list5.add("3");
        list5.add("4");
        list5.add("5");

        list6.add("1");
        list6.add("2");
        list6.add("3");
        list6.add("4");
        list6.add("5");

        list7.add("1");
        list7.add("2");
        list7.add("3");
        list7.add("4");
        list7.add("5");

        list8.add("1");
        list8.add("2");
        list8.add("3");
        list8.add("4");
        list8.add("5");

        list9.add("1");
        list9.add("2");
        list9.add("3");
        list9.add("4");
        list9.add("5");

        list10.add("1");
        list10.add("2");
        list10.add("3");
        list10.add("4");
        list10.add("5");

        hashMap.put(0,list1);
        hashMap.put(1,list2);
        hashMap.put(2,list3);
        hashMap.put(3,list4);
        hashMap.put(4,list5);
        hashMap.put(5,list6);
        hashMap.put(6,list7);
        hashMap.put(7,list8);
        hashMap.put(8,list9);
        hashMap.put(9,list10);

        rcv = (RecyclerView) findViewById(R.id.rcv);
        llom = new LinearLayoutManager(this);
        rcv.setLayoutManager(llom);
        adapter = new MainActivityAdapter(this, hashMap);
        rcv.setAdapter(adapter);

    }
}
</code></pre>

<p><strong>MainActivityAdapter</strong></p>

<pre><code>public class MainActivityAdapter extends RecyclerView.Adapter {
    private Context context;
    private static final int TEST = 0;
    private HashMap&lt;Integer, List&lt;String&gt;&gt; hashMap;

    public MainActivityAdapter(Context context, HashMap&lt;Integer, List&lt;String&gt;&gt; hashMap) {
        this.context = context;
        this.hashMap = hashMap;

    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new VpListItem(new ViewPagerListItem(context));


    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        ((VpListItem) holder).fillData(hashMap.get(position), position);

    }

    @Override
    public int getItemCount() {
        return hashMap.size();
    }


    public static class VpListItem extends RecyclerView.ViewHolder {
        private ViewPagerListItem otherArticlesListItem;

        public VpListItem(ViewPagerListItem itemView) {
            super(itemView);
            this.otherArticlesListItem = itemView;
        }

        public void fillData(List&lt;String&gt; list, int position) {
            otherArticlesListItem.fillData(list, position);

        }


    }
}
</code></pre>

<p><strong>ViewPagerListItem</strong></p>

<pre><code>public class ViewPagerListItem extends RelativeLayout {
    private Context context;
    private WrapContentViewPager vp;
    private ViewPagerAdapter adapter;
    private List&lt;String&gt; list = new ArrayList&lt;&gt;();


    public ViewPagerListItem(Context context) {
        super(context);
        this.context = context;
        setupView();
    }

    public ViewPagerListItem(Context context, AttributeSet attrs) {
        super(context, attrs);
        this.context = context;
        setupView();
    }

    public ViewPagerListItem(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        this.context = context;
        setupView();
    }

    private void setupView() {
        LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View view = inflater.inflate(R.layout.vp_list_item, this, true);
        vp = (WrapContentViewPager) view.findViewById(R.id.vp);
        adapter = new ViewPagerAdapter(context, list);
        vp.setAdapter(adapter);


    }

    public void fillData(List&lt;String&gt; list, int id) {
        vp.setId(id);
        this.list.addAll(list);
        adapter.notifyDataSetChanged();


    }
}
</code></pre>

<p><strong>ViewPagerAdapter</strong></p>

<pre><code>public class ViewPagerAdapter extends PagerAdapter {
    private Context context;
    private List&lt;String&gt; list;


    public ViewPagerAdapter(Context context, List&lt;String&gt; list) {
        this.context = context;
        this.list = list;


    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public int getItemPosition(Object object) {
        return POSITION_NONE;
    }

    @Override
    public boolean isViewFromObject(View view, Object object) {
        return view == (View) object;
    }

    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
        container.removeView((View) object);
    }

    @Override
    public Object instantiateItem(ViewGroup container, final int position) {

        CardListItem cardListItem = new CardListItem(context);
        cardListItem.fillData(list.get(position));
        container.addView(cardListItem);
        return cardListItem;
    }
}


CardListItem

    public class CardListItem extends LinearLayout {
    private Context context;
    private TextView tv;

    public CardListItem(Context context) {
        super(context);
        this.context = context;
        setupView();
    }

    public CardListItem(Context context, AttributeSet attrs) {
        super(context, attrs);
        this.context = context;
        setupView();
    }

    public CardListItem(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        this.context = context;
        setupView();
    }

    private void setupView() {
        LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View view = inflater.inflate(R.layout.card_list_item, this, true);
        tv = (TextView) view.findViewById(R.id.tv);


    }

    public void fillData(String text) {
        tv.setText(text);


    }
}
</code></pre>

<p>Then I scroll <code>RecyclerView</code> some time it lag . And I scroll <code>ViewPager</code> then I scroll <code>RecyclerView</code> some element (<code>ViewPager</code> that not scroll) change according to <code>ViewPager</code> that I scroll</p>

<p>Thank you.</p>