Search code examples
androidandroid-viewpagerandroid-recyclerview

Connect recyclerview to view pager


I have a recyclerview with pictures. I want to set it up in such a way that when I click the picture I get to see it full screen. Then I can swipe left and right to go to other pictures. Much like how a gallery app works. How can I do this?

Currently I have setup a view pager but whichever item in the recycler view I click I go to the view pager which starts from the first picture in the collection and not the picture I clicked on.


Solution

  • when you click on image ,, get index of this image and pass it to viewPager to open the same image

    viewPager.setCurrentItem(position);