views:

121

answers:

1

I'm trying to dynamically create TableRow objects and add them to a TableLayout. The TableRow objects have 2 items, a TextView and a CheckBox. The TextView items need to have their layout weight set to 1 to push the CheckBox items to the far right. I can't find documentation on how to programmatically set the layout weight of a TextView item.

Thanks

A: 

You have to use LinearLayout.LayoutParams with something like this:

TextView tv = new TextView(v.getContext());
tv.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, 1f));

The last parameter is the weight.

Macarse
I didn't mention this before, so I'm sorry. But I tried this prior to asking my question. It makes the TextView disappear from the layout. But, on a positive note, I found that setting the stretch_columns property of the TableLayout to 0 causes the effect I'm looking for (TextView's on the left, CheckBoxes on the right).Thanks for the help.
eugene