I need to show advertisements in my app with datas fetched from web services. I have displayed the ads in horizontal listview. Now I want each cell of the listview to be scrolled automatically at particular time interval (as like google ads). How can I do this ?
Asked
Active
Viewed 1,211 times
1 Answers
2
The best way, I think, is to use a handler in your activity, or fragment. Just add the code like this:
private Handler handler = new Handler();
handler.postDelayed(runnable, interval);
and in your runnable you should implement scrolling of your listview.
UPDATE If you will use ViewPager instead of scrollview you can make it this way:
final Handler handler = new Handler();
Runnable runable = new Runnable() {
@Override
public void run() {
//this will select next page number
page = page==maxPages? 0 : ++page;
//this will change the page to concrete page number
viewPager.setCurrentItem(page);
//this will execute this code after timeInterval
handler.postDelayed(this, timeInterval);
}
};
handler.postDelayed(runable, timeInterval);
where viewPager
is your ViewPager instance, timeInterval
- time interval in milliseconds after which you want to scroll the page, maxPages
- number of last page that you have in your ViewPager

Ilya Vorobiev
- 836
- 8
- 16
-
I dont want the ad to run horizontally. Instead it should move cell by cell(like image swiping in gallery) automatically – Nivedha S May 15 '15 at 06:41
-
so, may be it is better for you to use ViewPager instead of horizontal scrollview? It can move your items cell by cell – Ilya Vorobiev May 15 '15 at 06:49
-
If i use viewpager is it possible to move the cell automatically? – Nivedha S May 15 '15 at 06:54
-
Yes, but you still need a handler to do it with time interval. I've updated my answer to make it more clear – Ilya Vorobiev May 15 '15 at 07:12