android - Removing on click Listener from all buttons? -


I am making a simple 'Tic Tac Toe' game and so I have 9 buttons. One click is similar to the listener, which I have set in the layout on "click" property so that I do not need to create 9 buttons in the code to set the listener.

My problem is that I should remove all the listeners from the button when a game is won or tied.

Is there any way of loop through all the buttons without creating 9 button variables and setting every listener to empty?

My code:

  Click on Public Zero (see V) {button b = (button) v; Integer tag = integer.center (string) bitaget ()); Value [tag] = turnuplay; B.setText (turnToPlay); B.setOnClickListener (zero); PlayerTurn.setText ("Player" + Turnplay + "turn"); If (isBoardFull ()) {playerWon.setText ("Tie Game !!"); RemoveAllListeners ()} if (turnToPlay.equalsIgnoreCase ("X")) {turnToPlay = "O"; } And {turnToPlay = "X"; }}    

This function to cross the view tree and remove all the listeners You can use: Remove Public ZeroListener (see {View Topview = Matching (). GetDecorView (); TraverseTree (Topview); } Private Zero traversTree (see View) {If (View examples of ViewGroup) {ViewGroup Group = ViewGroup}; (Int Index = 0; Index & lieutenant; Group.GetChildCount (Index; Index ++) {TrojanSetry (Group.Jet ChildAut (Index)); }} And if (see example of button) {button button = (button) view; Button.setOnClickListener (zero); }}

Comments

Popular posts from this blog

mysql - BLOB/TEXT column 'value' used in key specification without a key length -

c# - Using Vici cool Storage with monodroid -

python - referencing a variable in another function? -