You dont need to create all the views dynamically. Just create xml for items and inflate it inside loop. Like..
MainActivity.java
public class MainActivity extends Activity {
private LinearLayout layoutmain;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
layoutmain = (LinearLayout) findViewById(R.id.layoutmain);
for (int i = 0; i <= 3; i++) {
View viewToLoad = LayoutInflater.from(MainActivity.this).inflate(
R.layout.row, null);
((LinearLayout) findViewById(R.id.layoutmain)).addView(viewToLoad);
}
TextView txt = new TextView(MainActivity.this);
txt.setText("Ship");
((LinearLayout) findViewById(R.id.layoutmain)).addView(txt);
for (int i = 0; i <= 3; i++) {
View viewToLoad = LayoutInflater.from(MainActivity.this).inflate(
R.layout.row, null);
((LinearLayout) findViewById(R.id.layoutmain)).addView(viewToLoad);
}
}
}
activity_main.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="PROCESSED" />
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<LinearLayout
android:id="@+id/layoutmain"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
</LinearLayout>
</ScrollView>
</LinearLayout>
row.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal" >
<TextView
android:id="@+id/txtfirst"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="07.23" />
<TextView
android:id="@+id/txtsecond"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="ORDER:0378945" />
<TextView
android:id="@+id/txtthird" android:gravity="center"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="$36.55" />
</LinearLayout>
OUTPUT :
