Java/Android: Handler and a for loop to show some elements of an array -
i have array buttons (10 buttons )
and want show these buttons delay using handler
but problem don't want show buttons !
i mean , saved buttons using sharedpreferences , buttons invisible in loop.
so here's thing , how can use handler.postdelayed
to show buttons aren't saved invisible ?
here's example:
button btn1 = (button)findviewbyid(r.id.btn1); button btn2 = (button)findviewbyid(r.id.btn2); button btn3 = (button)findviewbyid(r.id.btn3); button btn4 = (button)findviewbyid(r.id.btn4); button btn5 = (button)findviewbyid(r.id.btn5); // buttons array button mybtns[] = new button[]{btn1, btn2 , btn3 , btn4 , btn5}; // handler myhandler = new handler(); (int x=0; x<mybtns.length; x++) { if (!mysharedpreforsavedbtns.getboolean(mybtns[x].getid()+"",false)) { myhandler.postdelayed(new runnable() { public void run() { // how can show buttons 1 one ??? mybtns[x].setvisibility(view.visible); } }, 500 * x); } }
now how can show buttons 1 one ???
(int x = 0; x < mybtns.length; x++){ final int finalx = x; new handler().postdelayed(new runnable() { @override public void run() { mybtns[finalx].setvisibility(view.visible); } }, 500*x); }
or can use
handler uithreadhandler = new handler(); showdelayed(btn1, delaytime); showdelayed(btn2, delaytime); public void showdelayed(final view v, int delay){ uithreadhandler.postdelayed(new runnable() { @override public void run() { v.setvisibility(view.visible); } }, delay); }
hope work
Comments
Post a Comment