android - How To Change Background Resource of Button after Several Seconds -
i creating app memory game. button has image resource drawable , want background resource of button go default background, after 5 seconds.
here code.
collections.shuffle(shapesarray); this.myimg1=shapesarray.get(0); img1.setbackgroundresource(myimg1); task = new timertask(){ @override public void run() { // todo auto-generated method stub img1.setbackgroundresource(android.r.drawable.btn_default); } }; timer appear = new timer(); appear.schedule(task, 5000); img1.setonclicklistener(new onclicklistener(){ public void onclick(view v) { img1.setbackgroundresource(myimg1); string txt = pname.gettext().tostring(); if(txt.equals("heart")){ if(myimg1 == r.drawable.heart){ correct++; img1.setbackgroundresource(android.r.drawable.btn_default); } }
however, after 5 seconds, activity force closes , goes previous activity. i'm kinda new android. please help. :(
you can use either handler post delay or can use count down timer ,here giving example of count down , is-
new countdowntimer(30000, 1000) { public void ontick(long millisuntilfinished) { //this when click on each tick came here after 1000 millisecond } public void onfinish() { // after time experied here can change image printer.setbackgroundresource(r.drawable.prntr); } }.start();
thanks
Comments
Post a Comment