views:

55

answers:

3

I'm setting a textview as a child to a TableRow view programmatically and I cannot seem to get the text to wrap inside of the parent.

Here is the code which should be wrapping the text inside of the TableRow. Notice the setSingleLine is being set to false.

            TextView value = new TextView(this);
    ![alt text][1]value.setLayoutParams(new TableRow.LayoutParams(
            LayoutParams.FILL_PARENT,
            LayoutParams.WRAP_CONTENT));

    value.setSingleLine(false);
    value.setEllipsize(TruncateAt.END);
    value.setHorizontallyScrolling(false);

    value.setText(txt);
    value.setTextColor(Color.BLACK);
    value.setTextSize(12);
    value.setTypeface(generalFont);

The documentation doesn't say by setting it to false will make it multiline, it says it will restore it to the defaults.

setSingleLine(boolean singleLine) If true, sets the properties of this field (lines, horizontally scrolling, transformation method) to be for a single-line input; if false, restores these to the default conditions.

Does anybody have a code snippet or URL which points to a multiline TextView being created programmatically?

TEXT IN TEXT VIEW

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus tempus porttitor diam, sit amet rutrum nunc laoreet at. Mauris sit amet tristique e

IMAGE SHOWING THE ISSUE

TextView not wrapping

A: 

What you tried the setHorizontallyScrolling (boolean whether) method?

value.setHorizontallyScrolling(false); 

From the documentation:

Sets whether the text should be allowed to be wider than the View is. If false, it will be wrapped to the width of the View.

Cristian
I've updated the setHorizontallyScrolling and setEllipsize trying to get it to wrap, no luck. I've also updated the post above to include the text that is being set and an image of the rendering.
Gary
A: 

The problem ended it being the grand parent (TableLayout). I had to shrink all columns and the text wrapped.

table.setShrinkAllColumns(true);
Gary
A: 

You have to set the maximum Ems using setMaxEms(int) this will make your TextViews content be only X Ems wide.

Octavian Damiean