How to disable a Dynamic button by clicking another Dynamic button in android -


i creating 4 buttons dynamically in android in loop. number of buttons can increased 4 in other cases. trying disable other buttons while clicking 1 button. trying array of button object.

button btn[] = new button[4];  for(int i=0;i<4;i++) {   tablelayout layout = (tablelayout)findviewbyid(r.id.tableforevents);   btn[i]=new button(this);   btn[i].setid(i);   btn[i].settext("button"+i);   layout.addview(btn[i]);   btn[i].settext(i);    } 

this code giving me null pointer exception , results in application crash. unable perform next operation of enabling or disabling. kindly tell me solution or if there way solve problem

make sure r.id.tableforevents present in current layout activity. should getting layout null

also move below code outside loop (no need instantiate multiple times.)

tablelayout layout = (tablelayout)findviewbyid(r.id.tableforevents); 

Comments

Popular posts from this blog

javascript - Any ideas when Firefox is likely to implement lengthAdjust and textLength? -

matlab - "Contour not rendered for non-finite ZData" -

delphi - Indy UDP Read Contents of Adata -