Tengo estos campos de texto que generé dinámicamente. Pero parece que no puedo configurar los parámetros de diseño para ellos. Por favor dime que estoy haciendo mal.¿Cómo establecer dinámicamente los parámetros de diseño en Android?
Soy capaz de generar los campos sin parámetros de diseño. Sin embargo, si uso LayoutParams
, ni siquiera se genera.
Código:
TableLayout table = (TableLayout) findViewById(R.id.TableLayout1);
TableRow tr = new TableRow(this);
LinearLayout.LayoutParams trparams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
tr.setLayoutParams(trparams);
cg[i] = new EditText(this);
weight[i] = new EditText(this);
cg[i].setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_DECIMAL);
weight[i].setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_DECIMAL);
//Here's where it goes wrong. By adding fieldparams, the text field doesn't even get generated.
LinearLayout.LayoutParams fieldparams = new LinearLayout.LayoutParams(10, LinearLayout.LayoutParams.WRAP_CONTENT, 1.0f);
tr.addView(cg[i], fieldparams);
tr.addView(weight[i], fieldparams);
table.addView(tr);
¿Está utilizando linearlayout.layoutparams en una mesa? Se shud be tablerow.layoutparams – Amit
Buen comentario ... pero poca corrección Amit.it será TableLayout no TableRow – Sameer