Reputation: 207
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 ?
Upvotes: 2
Views: 1241
Reputation: 836
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
Upvotes: 2