java - Why i can't setEnable(false) for created dynamically buttons -


i creating 6/6 grid of buttons, using tablelayout , tablerow.

 private button mybutton;        private static final int  a=7;     private static final int  b=7;         private void createlayoutdynamically() {                 won = (tablelayout)findviewbyid(r.id.won);                  ( int qq = 1; qq < a; qq++) {                     tablerow tablerow = new tablerow(this);                     tablerow.setlayoutparams(new tablelayout.layoutparams(                              tablelayout.layoutparams.match_parent,                             tablelayout.layoutparams.match_parent,                             2                             ));                      won.setpadding(20,20,20,20);                     won.addview(tablerow);                  ( int q = 1; q < b; q++) {                      mybutton = new button(this);          }         }         } 

i have implemented coundowntimme, , when time ends want disable onclick buttons in grid.

public void inittimer(){           lol =new countdowntimer(czass, 100) {               public void ontick(long millisuntilfinished) {                   czass = millisuntilfinished;                  czas.settext("" + millisuntilfinished / 1000);                }              public void onfinish() {                  layout2.setvisibility(view.visible);                 ( int = 0; < won.getchildcount();  i++ ){                     view view = won.getchildat(i);                     view.setenabled(false);                 }               }             }.start();      } 

so got grid child, when time ended can still click buttons. why not disabled? u me ?


solution:

to clear, corrected @matiash's code fit code:

button buttons [][]= new button[a][b]; (int i=1;i<buttons.length;i++) {                      (int j=1;j<buttons[i].length;j++) {                          button btn = buttons[i][j];                          btn.setenabled(false);                     }                     } 

this do same fits posted code. come in handy.

this happening because getchildat() returns view: when calling setenabled() changing state of view, , not button.

api reference


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

ios - Change Storyboard View using Seague -