disposable = Observable
                            .interval(3000L, TimeUnit.MILLISECONDS)
                            .observeOn(AndroidSchedulers.mainThread())
                            .subscribe(aLong ->{
                                if(viewpager.getCurrentItem() <viewpagerAdapter.size() - 1){
                                    viewpaer.setCurrentItem(viewpager.getCurrentItem() + 1);
                                }else{
                                    viewpager.setCurrentItem(0);
                                }
                            });

onDestroy에서 dispoase()를 잊지말자 

 

 

참고:https://medium.com/mindorks/auto-viewpager-slider-using-rxjava2-fb1da80878bf

반응형

+ Recent posts