android - Change Variables in inner class -


so, problem that... i'm beginner java , android. want let boolean "active" become "true", when first button clicked (the thread necessary other part of code) then, when second button clicked & active == true, player1score becomes +1. problem can't use non-final variables in thread & onclicklistener, can't use final variables because need change them in code. if possible please give beginner-friendly answers, thanks!

    [...]     boolean active;     int player1score, player2score;      player1score = 0;     player2score = 0;       button button_launch = (button) findviewbyid(r.id.button_launch);     button_launch.setonclicklistener(new view.onclicklistener() {         public void onclick(view v) {              [...]              new thread(new runnable() {                 public void run() {                     [...]                      active = true;                  }              }).start();          }     });      [...]      button button_player1 = (button) findviewbyid(r.id.button1);     button_player1.setonclicklistener(new view.onclicklistener() {         public void onclick(view v) {              if(active == true){                  player1score++;             }         }     }); 

have @ java.util.concurrent.atomic.atomicboolean. think de want.


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

javascript - jQuery .height() return 0 when visible but non-0 when hidden -