Java(Android) stuck in while loop -


when run app continuously stuck in while loop. should leave while loop when button pressed, after pressing button continues loop.

view.onclicklistener listener11 = new view.onclicklistener() {         @override         public void onclick(view view) {             temp1 = button[0];             temp3 = button[0].getbackground();             state++;         }     };           while(state == 0) {             try {                 thread.sleep(500);             } catch (interruptedexception e) {                 e.printstacktrace();             }             button[0].setonclicklistener(listener11);         } 

variable: state int temp1 button temp3 drawable

the delay there because have 20 buttons , have setonclicklisteners buttons inside while loop think causes crash without delay. question possible have setonclicklisteners outside while loop still able check button clicks inside loop?

the problem pressing button while thread in sleeping state causing event not triggered , therefor state never change.


Popular posts from this blog