0

I am generating editTexts in a TableRow and the editTexts width is wrapping the content by default. I tried to set their width to match_parent like this:

TableRow tr = new TableRow(getActivity());
EditText et = new EditText(getActivity());

LayoutParams lparams = new TableRow.LayoutParams(
    LayoutParams.MATCH_PARENT,
    LayoutParams.WRAP_CONTENT);

et.setLayoutParams(lparams);

It did not change anything, but i can set their width if i replace LayoutParams.MATCH_PARENT with an integer. Could you please point me in the right direction to see why i cannot set their width to MATCH_PARENT?

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
Readdeo
  • 1
  • 1
  • go through https://stackoverflow.com/questions/50251052/how-to-change-the-width-of-an-edittext-object-programmatically/50251226?noredirect=1#comment87520668_50251226 – Rahul Chaudhary May 21 '18 at 10:23

1 Answers1

0

I accidentally found out, that if i am not using a TableRow, but placing the editTexts into the TableLayout its width will automaticall match the parent's width.

Readdeo
  • 1
  • 1