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>
UmarZaii
  • 1,355
  • 1
  • 17
  • 26
L4N0
  • 267
  • 1
  • 4
  • 7

1 Answers1

45

You can use:

TableRow.LayoutParams params = (TableRow.LayoutParams)editText.getLayoutParams();
params.span = toSpan;
editText.setLayoutParams(params); // causes layout update
Rich Schuler
  • 41,814
  • 6
  • 72
  • 59
  • but where it is stating that the layout_span = 2?? if I want to make layout_span=3 or layout_span=4?? then? – Sharda Singh Apr 10 '13 at 20:34
  • 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); – Sankar R.K Apr 28 '13 at 18:25
  • Nice, and there I was looking all over for a function that would return the span. Hidden in plain sight! – RTF Jan 12 '14 at 06:27