java - Android Table Cells Border -


this xml code below gives me proper border around table cells

<tablerow android:background="#cdcdcd" >     <textview android:text="1st column" android:background="#ffffff" android:layout_margin="2dip"/>    <textview android:text="2nd column" android:background="#ffffff" android:layout_margin="2dip"/>    <textview android:id="@+id/amount"  android:background="#ffffff"  android:layout_margin="2dip" android:text="3rd col"/> </tablerow> 

but when try programmatically doesn't work here code:

    datatable = (tablelayout)findviewbyid(r.id.data_table);                  tablerow tr=new tablerow(this);      counter++;     linearlayout.layoutparams lp = new linearlayout.layoutparams(layoutparams.wrap_content,layoutparams.wrap_content);     lp.setmargins(2,2, 2, 2);      textview tv= new textview(this);     tv.setlayoutparams(lp);     tv.settext("text"+counter);     tv.setbackgroundcolor(color.parsecolor("#ffffff"));                  counter++;      textview cb= new textview(this);     cb.setlayoutparams(lp);     cb.settext("text"+counter);     counter++;      textview ib= new textview(this);     ib.settext("text"+counter);     ib.setlayoutparams(lp);           tr.setbackgroundcolor(color.parsecolor("#cdcdcd"));     tr.setpadding(2, 2, 2, 2);     tr.addview(tv);     tr.addview(cb);     tr.addview(ib);     datatable.addview(tr,new tablelayout.layoutparams(layoutparams.wrap_content,layoutparams.wrap_content));  

every thing works except borders , when set "tv.setlayoutparams(lp);" parameters column disappears.

try add view calling addview(view child, int index, viewgroup.layoutparams params)

also, try create new layoutparams instance each view


Comments

Popular posts from this blog

php - mySql Join with 4 tables -

css - Text drops down with smaller window -

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -