user3415221 user3415221 - 3 months ago 12
Android Question

when is countdown start push data into array java

I am use frequency detector and when frequency will high i want start countdown with 10 $ and collect high frequency into data array.

if(maxAmpFreq > 3000){

Log.i("tag","start.......");
new CountDownTimer(10000, 1000) {
String test = String.valueOf(maxAmpFreq);
ArrayList<String> mylist = new ArrayList<String>();


public void onTick(long millisUntilFinished) {
Log.i("tag","A Kiss after 5 seconds");

mylist.add(test);

}

public void onFinish() {
Log.i("tag","your test is......"+mylist);
}
}.start();

}


but this not working correctly please guild me to solve this.

Answer

Problem is You declare your ArrayList Locally , That's why it have only one value at last. Every time its create new ArrayList .

Declare globally ....

private    ArrayList<String> mylist = new ArrayList<String>();

and use in the method for adding the value...

mylist.add(test);

NOTE:- Try to declare variable globally, which is used in whole class methods.