I have a RecyclerView displaying a list of images & and when a user clicks on one of the images e.g position 2, it takes them to a ViewPager with that same position & they can horizontally swipe to view other images from there.
The issue I am having is how to get that specific position & call instantiateItem
programmatically since on swiping, the user sees the same image.
My code
RecyclerView Adapter (should pass the position clicked to the ViewPager adapter)
public static int catPositionToView;
onBindViewHolder(...){
holder.recylerviewItem.setOnClickListener(v -> {
catPositionToView = position; //catPosition is a global static variable so that I can access it directly in the viewpager adaper
//I then launch the next activity which has a viewpager
context.startActivity(...)
}
}
ViewPager Adapter
@NonNull
@Override
public Object instantiateItem(@NonNull ViewGroup container, int position) {
Glide.with(context)
.load(myList.get(catPositionToView).getImage()) //Issue is here
.into(myImageView);
}
I can view the image of the passed position but how do I view other positions from there sequentially?