How to set layout_span through code
Asked Answered
A

1

24

Does anyone know how to set/change the android:layout_span="" of an EditText in Android at runtime. I already have the EditText defined in my XML file.

<TableRow android:paddingTop="20dip" android:gravity="center_horizontal">  

    <EditText android:layout_width="150dip" 
         android:text=""
         android:layout_height="40dip" 
         android:id="@+id/p"
         android:layout_span="2">
    </EditText>

</TableRow>
Assuan answered 9/1, 2011 at 1:46 Comment(0)
U
45

You can use:

TableRow.LayoutParams params = (TableRow.LayoutParams)editText.getLayoutParams();
params.span = toSpan;
editText.setLayoutParams(params); // causes layout update
Umbrian answered 9/1, 2011 at 1:57 Comment(3)
but where it is stating that the layout_span = 2?? if I want to make layout_span=3 or layout_span=4?? then?Wilser
params.span = toSpan; You can assign your span value either 2 or 3 or 4 to toSpan variable TextView txtView; params.span = 4; txtView.setLayoutParams(params);Havelock
Nice, and there I was looking all over for a function that would return the span. Hidden in plain sight!Purpure

© 2022 - 2024 — McMap. All rights reserved.