Reputation: 65
Hey guys i want to put 2 second delay in each code inside of the arraylist. How can i do this? Sorry newbie in android developing. Thanks for any help.
Here is my code.
private ArrayList<double[]> points = new ArrayList<>();
{
points.add( new double[] {-2885, 4537} );
points.add( new double[] {-2903, 3916} );
points.add( new double[] {-3236, 3883} );
points.add( new double[] {-3233, 3657} );
points.add( new double[] {-3552, 3638} );
points.add( new double[] {-3570, 2661} );
points.add( new double[] {-2735, 2651} );
points.add( new double[] {-2720, 2613} );
points.add( new double[] {-2634, 2613} );
}
Upvotes: 0
Views: 177
Reputation: 71
You can use Thread class to make delay during the execution.
try{
Thread.sleep(seconds to delay*1000)
}
catch(Exception e)
{
e.printStackTrace();
}
or you can use the Asynchronous Task to delay
public void callAsynchronousTask() {
final Handler handler = new Handler();
Timer timer = new Timer();
TimerTask doAsynchronousTask = new TimerTask() {
@Override
public void run() {
handler.post(new Runnable() {
public void run() {
try {
Log.e("data","5 sconds");
} catch (Exception e) {
// TODO Auto-generated catch block
}
}
});
}
};
timer.schedule(doAsynchronousTask, 0, 5000); //execute in every 5 s
}
Upvotes: 1