Reputation: 77
I'm currently creating an Ultimate Tic Tac Toe app which consists of 81 buttons. The way I handled it when it was regular tic tac toe was to make a switch statement for 9 buttons. I'm just wondering if creating a switch for all 81 buttons is still the best way to handle all the button presses?
Upvotes: 1
Views: 318
Reputation: 11086
For all elements set onClick with a same name:
<LinearLayout
//blah blah
android:onClick="myClickFunction"
/>
and then in your Java file you will need only this one click Listener:
public void myClickFunction(View v) {
String mytag=(String) v.getTag();
// And do something with tag or id
}
Upvotes: 1
Reputation: 1813
Inside the OnClick
event you have the view.
Work with it directly
Upvotes: 1