0

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;
besplash
  • 346
  • 1
  • 5
  • 17
  • remove this line in your code "row.setWeightSum(1.0f);" and try again, it will work. – balaji koduri Dec 22 '13 at 16:00
  • what does "not working" mean? Also, in the line `row.setLayoutParams(new LayoutParams...` you should use the `LayoutParams` of the view your `TableRow` resides in. http://stackoverflow.com/questions/2965662/how-do-you-setlayoutparams-for-an-imageview – dst Dec 22 '13 at 16:00
  • @balajikoduri still doesnt work – besplash Dec 22 '13 at 16:04
  • @dst with not working I mean, that I get every EditText, but they are all set to "wrap_content" .. I dont exactly understand, what you mean, but I tried to use "row.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT,TableRow.LayoutParams.WRAP_CONTENT));" if that is what you mean, still doesnt work though – besplash Dec 22 '13 at 16:06
  • From looking at your code I'd guess I ment `TableLayout.LayoutParams`. You did not post the part relevant for that; I'm however not sure if this has something to do with the issue (was more a stylistic comment, to prevent bugs). Did you try the XML? As from the documentation I read, `TableRow` (when placed inside a `TableLayout`) should override the layout params to be ` MATCH_PARENT` and `WRAP_CONTENT`, no matter what you set. Why don't you use columns? Did you read http://developer.android.com/reference/android/widget/TableLayout.html? – dst Dec 22 '13 at 16:17
  • I posted everything I used for this part. The whole thing works in xml, but not in Java.. Thats why I didnt try to use columns, because others solved their problems and its working for them. I didnt read the reference, because I usually dont understand them – besplash Dec 22 '13 at 16:24

0 Answers0