Ho questi campi di testo che ho generato dinamicamente. Ma non riesco a impostare parametri di layout per loro. Per favore dimmi cosa sto sbagliando.Come impostare dinamicamente i parametri di layout in Android?
Sono in grado di generare i campi senza parametri di layout. Tuttavia, se utilizzo LayoutParams
, non viene nemmeno generato.
Codice:
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);
È possibile utilizzare linearlayout.layoutparams su una tabella? Shud be tablerow.layoutparams – Amit
Bel commento ... ma piccola correzione Amit.it sarà TableLayout not TableRow – Sameer