thinkandapply wrote:How do i display a multi line string on the screen of a mobile device,
i used this way
String str="This is a simple text/n"+"but doesn't display multiline";
private void TextOut(String text, Graphics g, int x, int y, int textSize, int color) {
int previousColor = g.getColor();
String cmdBreakText = "/n";
int lineNo = 0;
String[] strLine = new String[6];
int charLineAt = 0;
// go through each char in a text
for (int i = 0; i < text.length() - cmdBreakText.length(); i++) {
// check if that text contain the command break
if ( text.substring( i, i + cmdBreakText.length() ).equals(cmdBreakText)) {
strLine[lineNo] = text.substring( charLineAt, i );
// for the next check, begin after the cmd break text
charLineAt = i+cmdBreakText.length();
// get the total lines (-1)
lineNo++;
}
}
strLine[lineNo] = text.substring( charLineAt, text.length() );
// set paint color
g.setColor(color);
for (int i = 0; i < lineNo+1; i++) {
g.drawString(strLine[i], x, y + i*textSize, Graphics.LEFT|Graphics.TOP);
}
// set paint to previous color
g.setColor(previousColor);
}TextOut("Hello world! /nWelcome to /nhttp://www.smackall.com/mobile-game-developer//nHave a nice day! ^^", g, 50, 50, 12, 0x0000FF);Users browsing this forum: No registered users and 3 guests