androidandroid-viewpagerviewpagerindicator

Use Arrow for navigation in viewPager android ? i have tried different example but not succeded


-what i want is..user can move to next image by sliding as well as by using right or left arrow.. i am able to slide..but arrows are not working.


Solution

  • If you want it to work with sliding as well as arrows then you have to use left and right listeners like this.

        right.setOnClickListener(new View.OnClickListener(){
            @Override
            public void onClick(View v) {
                if(pager.getCurrentItem() < pager.getRight())
                pager.setCurrentItem(pager.getCurrentItem()+1,true);
            }
        });
    
        left.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (pager.getCurrentItem() > pager.getLeft())
                    pager.setCurrentItem(pager.getCurrentItem()-1,true);
            }
        });