I already looked for this all over the internet and also here, but somehow no solution worked for me.. I want to do this in Java (this is XML-Code):
<TableRow
android:id="@+id/tableRow1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<EditText
android:id="@+id/editText1"
android:layout_width="0px"
android:layout_height="wrap_content"
android:ems="10"
android:layout_weight="50" />
<EditText
android:id="@+id/editText2"
android:layout_width="0px"
android:layout_height="wrap_content"
android:ems="10"
android:layout_weight="20"
android:inputType="number" />
<EditText
android:id="@+id/editText3"
android:layout_width="0px"
android:layout_height="wrap_content"
android:ems="10"
android:layout_weight="30"
android:inputType="date" />
</TableRow>
I cannot get it working.. I could post every code that I tried, but I think that may be too much, so I just post the last one I have atm:
case R.id.add:
TableLayout lout = (TableLayout) findViewById(R.id.lout);
TableRow row = new TableRow(this);
TableRow.LayoutParams objparams = new TableRow.LayoutParams(
TableRow.LayoutParams.MATCH_PARENT,
TableRow.LayoutParams.WRAP_CONTENT, 0.5f);
row.setId(300+elements);
row.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT));
lout.addView(row);
EditText obj = new EditText(this);
obj.setText("text");
obj.setId(1+(29+elements));
obj.setTextColor(Color.WHITE);
EditText obj2 = new EditText(this);
obj2.setText("text");
obj2.setId(2+(29+elements));
obj2.setTextColor(Color.WHITE);
EditText obj3 = new EditText(this);
obj3.setText("text");
obj3.setId(3+(29+elements));
obj3.setTextColor(Color.WHITE);
obj.setLayoutParams(objparams);
row.setWeightSum(1.0f);
row.addView(obj);
objparams.weight = 0.2f;
obj2.setLayoutParams(objparams);
row.addView(obj2);
objparams.weight = 0.3f;
obj3.setLayoutParams(objparams);
row.addView(obj3);
elements+=3;
break;