I have a TextView
and I would like to update the TextView
every 5 second with each string in my String Array.
Here is the code I tried. It always shows only the last String in the String array.
TextView display;
EditText caption;
Thread thread;
String blinks;
String[] wc;
private CountDownTimer timer;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
display = (TextView) findViewById(R.id.display);
caption = (EditText) findViewById(R.id.caption);
timer = new CountDownTimer(5000, 20) {
@Override
public void onTick(long millisUntilFinished) {
String[] wc = {"The","Qucik", "Brown","fox","Jumped"};
for (int j = 0; j < wc.length; j++) {
blinks = wc[j];
final String[] titles = {"" + blinks + ""};
for (int i = 0; i < titles.length; i++) {
display.setText(titles[i]);
}
}
}
@Override
public void onFinish() {
try{
yourMethod();
}catch(Exception e){
}
}
}.start();
}
You need to make sure that you call
TextView.setText()
only once per tick. Then you can go with your approach (CountDownTimer
) or with Antrrommet's (Handler
). With your approach, this will look like something like:try to play Around with handler in android , i think you are asing something like this :
If the answer is useful. Please do vote :)