I am using layout inflator to generator dynamic text views, edit text and buttons in android. Everything is working fine but I am getting an extra button, edit text and text view . I am populating the value of text views dynamically and it too starts populating from second text view. Here is my code. My xml code,
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/scrollview"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:id="@+id/linearlayoutid"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="@+id/textviewid"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<EditText
android:id="@+id/edittextid"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/linearlayoutid"
android:layout_centerHorizontal="true"
android:text="button" />
</LinearLayout>
My code in for populating values dynamically,
setContentView(R.layout.activity_main);
LinearLayout lv = (LinearLayout) findViewById(R.id.linearlayoutid);
for (int i = 0; i < 41; i++) {
TextView[] myTextViews = new TextView[41];
EditText[] editTextarray = new EditText[41];
View v = LayoutInflater.from(this).inflate(R.layout.activity_main, null);
TextView tv= (TextView) v.findViewById(R.id.textviewid);
EditText editText = (EditText) v.findViewById(R.id.edittextid);
myTextViews[i] = tv;
myTextViews[i].setText(d.get(i));
editTextarray[i] = editText;
editText.setCursorVisible(true);
lv.addView(v);
}
I am getting an additional textview, edittext and button in layout. I must get only 41 but I am getting 42 with first one being "empty" or no values populated. Any help would be glad. ! Thanks