Smittey
Smittey

Reputation: 2492

Android - Formatting a TextView

I created a simple word search which works in normal Java where it prints out a 2D array of the letters. Everything is perfectly inline and looking nice, but when trying to turn this into an android app, none of the letters are inline.

My code is the following:

TextView wordGrid = (TextView) findViewById(R.id.wordSearch);  
String grid = "";

    for(int i=0; i<matrix.length; i++)
    {
    grid += i + "   ";

        for(int j=0; j<matrix.length; j++)
        {
            grid +=  matrix[i][j] + " ";
        }
        grid += "\n";
    } 

    wordGrid.setText(grid);

The main.xml document contains the following attributes for 'wordSearch'

<TextView
android:id="@+id/wordSearch"
android:layout_width="400px"
android:layout_height="400px"
android:textSize="18sp"
android:layout_x="41dp"
android:layout_y="25dp" />

I can't get it to display all of the letters inline. Any help is greatly appreciated.

Thanks

Upvotes: 0

Views: 439

Answers (1)

DDas
DDas

Reputation: 306

Try this:

wordGrid.setText( Html.fromHtml( grid ) );

Upvotes: 1

Related Questions