views:

37

answers:

1

Hi all

I tried to write some text on a surface view I created. It works fine, if title is false, and there is no linebreak added to the text. But if I add a title and therefore a linebreak, the linebreak isn't printed as expected, but instead there is this symbol [] printed.

Any hints why?

@Override
public void drawObject() {
String text = "";
if (title) {
   text = getGameBoard().getGame().getForeignProfile().getName() + "\n";
}
text = text + getScoreAsString();
getGameBoard().getCanvas().drawText(text, 0, text.length(), getPosition().getX(), getPosition().getY(), getPaint());
}
+1  A: 

The [] symbol is probably your newline character. For whatever reason, drawText() doesn't know how to handle newlines.

Either strip the newline, or call drawText() twice with an offset Y-position to simulate a newline.

Trevor Johns
thanks. I didn't know it doesn0t supports newline. thats really annoying. what do you mean with strip the newline?
Roflcoptr
Use String.replace() to replace all instances of "\n" with "" (an empty string).
Trevor Johns
ah yes that's not the problem, the code above is the single situation where i need it ;) and as you can see it added the "\n" by myself
Roflcoptr