by harks44 » Sun Feb 26, 2012 4:27 pm
Thanks for the answer.
I have made a printBoard method in java looking like this:
public static void printBoard(Board board) {
// keeps track of tiles.
for (int row = 0; row < 4; row++) {
for (int col = 0; col < 4; col++) {
if (board.getTile(row, col).getValue() == 0)
System.out.print(" "); // keeps track of the empty tile and prints a blank instead of 0.
else
System.out.printf("%-3d", board.getTile(row, col)
.getValue()); // formats the board and keeps track of tiles and the values .
}
System.out.println(); // for formating
}
}
Now I want to convert it to Android.. tried something like this:
public void printBoard(){
print = (TextView) findViewById(R.id.tvPrint);
for(int row = 0; row < 4; row++)
{
for (int col = 0; col < 4; col++)
{
if (board.getTile(row, col).getValue() == 0)
print.setText(" ");
else
print.setText(board.getTile(row, col).getValue());
}
print.setText("\n");
}
}
This doesn't work at all crashes upon startup.
I quess it has something to do with my else statement.Tried use append and just written out 0-15 with print.append(String format( "%3s", row*4+col) and it works. It's my getTile method in my Board-class, but i want to refer to it just by method name instead of creating it all over again in printBoard method.