android - How Do I Pause and Resume a For Loop? -
i'm noob android , trying cycle text arraylist of strings , display them in textswitcher. want text alter every 2 seconds. used this question guide , have no problem switching text button. however, when seek cycle text loop 2 sec delay shows first text arraylist. how can create loop continuously execute pause? help appreciated.
my code;
private void updatecounter() { try{ (int i=0; i< coinshowreader.tickercontent.size(); i++){ mhandler.postdelayed(new runnable() { public void run() { m_switcher.settext((coinshowreader.tickercontent.get(coinshowreader.m_counter))); coinshowreader.m_counter++; } }, 2000); } }catch(exception e){ e.printstacktrace(); } }
remove loop, don't need it, schedule anther runnable within handler this:
void updatetextview(){ m_switcher.settext((coinshowreader.tickercontent.get(coinshowreader.m_counter))); coinshowreader.m_counter++; mhandler.postdelayed(new runnable() { public void run() { updatetextview(); } } ,2000); } }
that way every phone call updatetextview()
schedule next phone call , on ...
note: don't forget insert trigger stop behavior because it's infinity
android multithreading loops wait postdelayed
No comments:
Post a Comment