Skip to content Skip to sidebar Skip to footer

Add Next, Prev Buttons In Image Slider Made By Recyclerview

I've made Image slider with the help of recyclerView and SnapHelper. I have also added next, prev imageView under the recyclerView. I want to implement them to work as next,prev.

Solution 1:

add this in your main class

int CurrenePosition = ((LinearLayoutManager)recyclerView.getLayoutManager()).findFirstVisibleItemPosition();
NextItemImageView.setOnClickListener(new View.OnClickListener() {
    @Override
        public void onClick(View v) {
            if (CurrenePosition < recyclerView.getAdapter().getItemCount()-1)
            recyclerView.scrollToPosition(CurrenePosition + 1);
        }
    });
PreviousItemImageView.setOnClickListener(new View.OnClickListener() {
    @Override
        public void onClick(View v) {
            if (CurrenePosition > 0)
            recyclerView.scrollToPosition(CurrenePosition - 1);
        }
    });

Post a Comment for "Add Next, Prev Buttons In Image Slider Made By Recyclerview"