Tuesday, July 26, 2011

[android-developers] Re: A little help with layout params in code.

No responses so either my question stumped everyone or it was too
obvious for anyone to bother :) Either way I finally got it to work
so if it saves anyone else 4 days of pouring over documentation here
is the code.

if (v.getId()==R.id.add_row) {
mRowCount++;
TableLayout table =
(TableLayout)findViewById(R.id.the_table);
TableRow row = new TableRow(this);
TextView tv1 = new TextView(this);
TextView tv2 = new TextView(this);
ImageView iv = new ImageView(this);
tv1.setText("Table row
#"+Integer.toString(mRowCount));
tv1.setGravity(Gravity.LEFT);
TableRow.LayoutParams trp = new
TableRow.LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.FILL_PARENT,Gravity.LEFT);
row.addView(tv1, trp);
iv.setImageResource(R.drawable.divider);
row.addView(iv, trp);
tv2.setText("Add more text here.");
row.addView(tv2, trp);
table.addView(row);
}

--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

No comments:

Post a Comment