Reputation: 65
I would like to call some functions at an interval of time. How could I use a Timer in Android to achieve this?
This is my piece of code
for(int j=0;j<i;j++)
{imb_items[j].startAnimation(myFadeInAnimation);}
I want to run an animation for each of these imageViews, which I keep in imb_items[], but I don't want the images to overlap, so I have to start the animations at different periods of time.
thank you!
Upvotes: 2
Views: 163
Reputation: 65
Solution:
for(int j=0; j<i;j++) {
translateAnim[j].setStartOffset(5000*j);
imb_items[j].startAnimation(translateAnim[j]);
}
Upvotes: 0
Reputation: 3017
Use this.. call your function from run().
Timer timer = new Timer();
timer.scheduleAtFixedRate(new TimerTask() {
@Override
public void run() {
// TODO Auto-generated method stub
runOnUiThread(new Runnable() {
public void run() {
// TODO Auto-generated method stub
yourfunction();
}
});
}
}, 0, 10000);
Upvotes: 2