java - How to keep both components from XML and those added programatically -
i new android.
i drawing textfield using drag-drop eclipse.
also adding table programatically.
but can see table added programatically.
how keep both components xml , added programatically.
sorry if basic , stupid question.
here code
<?xml version="1.0" encoding="utf-8"?> <tablelayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/tablelayout1" android:layout_width="match_parent" android:layout_height="match_parent" android:shrinkcolumns="*" android:stretchcolumns="*"> <edittext android:id="@+id/edittext1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:ems="10" > <requestfocus /> </edittext> <zoombutton android:id="@+id/zoombutton1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@android:drawable/btn_plus" /> <zoomcontrols android:id="@+id/zoomcontrols1" android:layout_width="wrap_content" android:layout_height="wrap_content" /> <twolinelistitem android:id="@+id/twolinelistitem1" android:layout_width="wrap_content" android:layout_height="wrap_content" /> <absolutelayout android:layout_width="wrap_content" android:layout_height="wrap_content" > </absolutelayout> <edittext android:id="@+id/edittext2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:ems="10" android:inputtype="textpassword" /> <analogclock android:id="@+id/analogclock1" android:layout_width="wrap_content" android:layout_height="wrap_content" /> <calendarview android:id="@+id/calendarview1" android:layout_width="match_parent" android:layout_height="match_parent" /> </tablelayout>
and
@override public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); databasehandler db = new databasehandler(this); //to insert // db.addcontact(new contact("ninad", "9893353432")); tablelayout table = new tablelayout(this); table.setstretchallcolumns(true); table.setshrinkallcolumns(true); tablerow rowtitle = new tablerow(this); rowtitle.setgravity(gravity.center_horizontal); tablerow rowdaylabels = new tablerow(this); // title column/row textview title = new textview(this); title.settext("contacts"); title.settextsize(typedvalue.complex_unit_dip, 18); title.setgravity(gravity.center); title.settypeface(typeface.serif, typeface.bold); tablerow.layoutparams params = new tablerow.layoutparams(); params.span = 3; rowtitle.addview(title, params); // header 1 textview header1 = new textview(this); header1.settext("id"); header1.settypeface(typeface.serif, typeface.bold); rowdaylabels.addview(header1); // header 2 textview header2 = new textview(this); header2.settext("name"); header2.settypeface(typeface.serif, typeface.bold); rowdaylabels.addview(header2); // header 3 textview header3 = new textview(this); header3.settext("phone"); header3.settypeface(typeface.serif, typeface.bold); rowdaylabels.addview(header3); // add table table.addview(rowtitle); table.addview(rowdaylabels); list<contact> contacts = db.getallcontacts(); tablerow rowhighs = null; (contact cn : contacts) { rowhighs = new tablerow(this); // data textview day1high = new textview(this); day1high.settext(string.valueof(cn.getid())); rowhighs.addview(day1high); textview day2high = new textview(this); day2high.settext(cn.getname()); rowhighs.addview(day2high); textview day3high = new textview(this); day3high.settext(cn.getphonenumber()); rowhighs.addview(day3high); table.addview(rowhighs); } setcontentview(table); }
my table in oncreate
method populated properly, components xml lost.
update :
what found is, setting 2 times , later 1 overwritting it
setcontentview(r.layout.activity_main); setcontentview(table);
but how can merge ?
type in activity below oncreate
tablelayout tbl_lay=(tablelayout)findviewbyid(r.id.tablelayout1); ..... ..... ..... code..... tablelayout tb=new tablelayout(this); ..... .....
atlast add these line
tbl_lay.addview(tb);
it you
Comments
Post a Comment