thatboytitz
thatboytitz

Reputation: 77

Handling android onclick for multiple buttons (81 total)

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?

Ultimate Tic Tac Toe

Upvotes: 1

Views: 318

Answers (2)

Ali Sheikhpour
Ali Sheikhpour

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

Lionel Briand
Lionel Briand

Reputation: 1813

Inside the OnClick event you have the view.

Work with it directly

Upvotes: 1

Related Questions