android - Dynamicaly add layout in layout? -
i have layout , need insert in kind of blocks text - comments date, name, text. there way use this
(int r=0; r<10;r++) { textview t1=(textview) findviewbyid(r.id.text1); t1="blabla"; mainlayout.add(commentlayout); }
so listview without adapter , etc.
<relativelayout android:layout_width="fill_parent" android:layout_height="fill_parent" xmlns:android="http://schemas.android.com/apk/res/android"> <textview android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="name" android:id="@+id/comm_name" android:layout_marginleft="20dp" android:layout_margintop="24dp" android:layout_alignparenttop="true" android:layout_alignparentleft="true" android:layout_alignparentstart="true" /> <textview android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="date" android:id="@+id/comm_date" android:layout_alignparenttop="true" android:layout_alignparentright="true" android:layout_alignparentend="true" android:layout_margin="20dp" /> <textview android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="new text" android:layout_alignparenttop="true" android:layout_alignparentleft="true" android:layout_alignparentstart="true" android:layout_margintop="60dp" android:layout_marginleft="20dp" android:id="@+id/comm_text" />
you can it, way doing throw exception, because findviewbyid
returns same object, , after first iteration t1
has parent. should create new instance of textview
programmatically, @ every iteration.
Comments
Post a Comment