Android design unknow comment count layout programical

in my applicationi want to design this layout programical:

enter image description here

i have ViewGroup as LinearLayout in main layout:

<LinearLayout
        android:id="@+id/inclusionlayout"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:layout_marginTop="50dp"/>

now i have other desinged layout with layout_comments filename as :

<LinearLayout
        android:orientation="vertical"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">
    <TextView
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:text="New Text"
            android:id="@+id/tv_comment_text" android:gravity="center_vertical|right"/>
</LinearLayout>

now i want to attach unlimited this layout into inclusionlayout for example:

ViewGroup inclusionViewGroup = (ViewGroup) findViewById(R.id.inclusionlayout);
for (int i = 0; i <= 4; i++) {
    String comment = "Comment: test " + i ;
    View child = LayoutInflater.from(this).inflate(R.layout.layout_comments, null);
    inclusionViewGroup.addView(child);

    TextView comment_text = (TextView) findViewById(R.id.tv_comment_text);
    comment_text.setText(comment);

}

unfortunatelly in this phase i have only one child row, and all childs dont add into into inclusionlayout


Source: android

Leave a Reply