Take the 2-minute tour ×

I want to do a board game similar to tic tac toe (but in my game it is 5*5). In the very beginning, I just want to implement a player vs player version, later on I will add AI. I went through some example of tic tac toe and saw some developers used buttons(for the squares) and table layout for the board. But for the 5*5 or higher dimension, is this still a good way to do so? Or is it generally a good practice to use table layout and button for such kind of situation? If Not, what should I use? Please provide some tutorial/example/links. I appreciate that.

share|improve this question

closed as not constructive by PearsonArtPhoto, Sam, Ryan Bigg, kiamlaluno, AAA Nov 14 '12 at 5:10


2 Answers 2

up vote 1 down vote accepted

Before you start looking for something fancier, you should start with something that you know will work and optimize if it becomes an issue. In your use case, do you ever anticipate that your tic-tac-toe would use up enough resources to start slowing down the system? I'd imagine not. You could do it with a RelativeLayout and define the positioning yourself with the View attributes, but again, I don't see that it buys you anything.
If you are worried about performance then you should follow other best practices like having all your Button objects as class members for your Activity so that you are only calling findViewById() once per view and then your onClickListener can update any view it wants without having to look it up. If you're building one of your first apps, something like that will get you a lot farther than trying to implement some exotic layout.
In general, TableLayout is fine if you know ahead of time how many rows / columns you need. Which would suite your use case. It can take a hit if you are trying to dynamically change its dimensions; which I'd really hope you're not doing in tic-tac-toe (some might call that cheating)

share|improve this answer

You must use a TableLayout with buttons. It'll make your life easier and it won't be so expensive in terms of performance. You may also create a custom view for the board, but it won't worth it.

share|improve this answer
I see. How about a chess game? Or a Reversi? –  user1701840 Nov 13 '12 at 3:16
You'll have usability issues if the number of tiles increases a lot, since they will be very small to touch on a phone. In this case, you must consider implementing a zooming mechanism. In that approach, a custom view fits better. –  Flávio Faria Nov 13 '12 at 3:21
