Arul Harsh
Arul Harsh

Reputation: 1

ViewPager Auto Scroll with Specific Duration of Each Item

So Basically in My app on the Home Screen i want to show Some Ads Using Viewpager and I got Those Ads from an API. I also Get Ads Duration Form the API. Now, If the First Ad Duration is 10 Second then i need to show the First Item of Viewpager for 10 Seconds and then Scroll it to next item. Now if duration of next item is 25 second then it should show for 25 Seconds and then Scroll to next item and so on i want to repeat the=is cycle again and again. Also These ads can be both Image and Video Can you Please Suggest a beter way to do it

I Try Usign Handler adn Timer

public void setupAutoPager(final int size) {

        final Handler handler = new Handler();

        currentPage = viewpager.getCurrentItem();

        final Runnable update = new Runnable() {
            public void run() {
                if (currentPage == size - 1) {

                    // Add the fragment to your fragmentArray
                    // Only the rank 0 needs to be taking care, works like in queue

                    // Set the next item
                    viewpager.setCurrentItem(currentPage + 1);

                    //yourFragmentArray.remove(0);

                    // Update the size

                }
                else {
                    viewpager.setCurrentItem(currentPage + 1);
                }
            }
        };

        Timer timer = new Timer();
        timer.schedule(new TimerTask() {

            @Override
            public void run() {
                handler.post(update);
            }
        }, 500, newAdsMediaiList.get(viewpager.getCurrentItem()-1).getDurationTime());
    }`

But it Doesnt Work as Expected

Upvotes: 0

Views: 17

Answers (0)

Related Questions