android - extend tablerow view -
i trying programmatically create xml view extending tablerow view:
<tablerow android:id="@+id/tablerow1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_vertical" android:gravity="center_vertical" android:weightsum="1.0" > <button android:id="@+id/tester_button" style="?android:attr/buttonstylesmall" android:layout_weight=".2" android:layout_width="0dip" android:layout_height="wrap_content" android:text="a" /> <textview android:id="@+id/textview2" android:layout_width="0dip" android:layout_height="fill_parent" android:gravity="center" android:layout_weight=".7" android:text="column 1" android:textappearance="?android:attr/textappearancelarge" /> <checkbox android:id="@+id/checkbox1" android:layout_weight=".1" android:layout_width="0dip" android:layout_height="wrap_content" /> </tablerow>
this class of extended row:
public class categoryrow extends tablerow { layoutparams rowparams = new tablerow.layoutparams(layoutparams.wrap_content, layoutparams.wrap_content, gravity.center); layoutparams innerparams = new tablerow.layoutparams(0, layoutparams.wrap_content, gravity.center); checkbox check; button arrowbutton; textview categorytitle; public categoryrow(context context) { super(context); this.setlayoutparams(rowparams); this.setgravity(gravity.center); this.setweightsum(1); check = new checkbox(context); innerparams.weight = (float) 0.1; check.setlayoutparams(innerparams); arrowbutton = new button(context); innerparams.weight = (float) 0.2; arrowbutton.setlayoutparams(innerparams); arrowbutton.settext("a"); categorytitle = new textview(context); innerparams.weight = (float) 0.7; categorytitle.setlayoutparams(innerparams); categorytitle.settextappearance(context, android.r.attr.textappearancelarge); //add views row this.addview(arrowbutton); this.addview(categorytitle); this.addview(check); } public void setcategorytitle(string title){ categorytitle.settext(title); } public void checkcategory(){ check.setchecked(true); } public void uncheckcategory(){ check.setchecked(false); } }
in activity adding categoryrow
view tablelayout
addview
function.
public class notificationcategorise extends activity { tablelayout categoryconteiner; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_notification_categorise); categoryconteiner = (tablelayout) findviewbyid(r.id.categories_conteiner); categoryrow categoryrow = new categoryrow(this); categoryrow.setcategorytitle("bla"); categoryconteiner.addview(categoryrow); }
my problem categoryrow
not added activity sceen.
i have changed extended class code, , worked fine.
import android.content.context; import android.view.gravity; import android.widget.button; import android.widget.checkbox; import android.widget.tablerow; import android.widget.textview; public class categoryrow extends tablerow { layoutparams rowparams = new tablerow.layoutparams(layoutparams.match_parent, layoutparams.match_parent); layoutparams innerparams1 = new tablerow.layoutparams(0, layoutparams.match_parent, gravity.center); layoutparams innerparams2 = new tablerow.layoutparams(0, layoutparams.match_parent, gravity.center); layoutparams innerparams3 = new tablerow.layoutparams(0, layoutparams.match_parent, gravity.center); checkbox check; button arrowbutton; textview categorytitle; public categoryrow(context context) { super(context); this.setlayoutparams(rowparams); this.setweightsum(1f); check = new checkbox(context); innerparams1.weight = 0.1f; check.setlayoutparams(innerparams1); arrowbutton = new button(context); innerparams2.weight = 0.2f; arrowbutton.setlayoutparams(innerparams2); arrowbutton.settext("a"); categorytitle = new textview(context); categorytitle.setgravity(gravity.center); innerparams3.weight = 0.7f; categorytitle.setlayoutparams(innerparams3); categorytitle.settextappearance(context, android.r.attr.textappearancelarge); //add views row this.addview(arrowbutton); this.addview(categorytitle); this.addview(check); } public void setcategorytitle(string title){ categorytitle.settext(title); } public void checkcategory(){ check.setchecked(true); } public void uncheckcategory(){ check.setchecked(false); } }
Comments
Post a Comment