I am making a TicTacToe app, and I have an array of 3×3 ImageButtons. They all have the onClick method, and I would like to be able to get the clicked ID, for example, id the ImageButton identifier is ImageButton01, get the 01.
I have a method to get the line and column where the button is, so I can localize the Button inside the array. Then I have a method called mark(), which sets the ImageButtons ImageResource to a cross or a circle. I have to pass the coordinates of the button in the array to the mark method, so I need to get the coordinates from the Button ID.
How can I do this?
The numeric id of the button can be obtained in click listener by
view.getId(). But if you got 3×3 matrix I’d just create 3×3 array and put button ids there and then look it up when needed (or create hash map with button id being the key and store all additional information there). Many options.