Problem of adding dynamic view to Linringayout

I want to add some views to LinearLayout . Here is the code I use to add the addition of several views to LinearLayout .

Java code:

 LinearLayout seriesMainListItemView = (LinearLayout) findViewById(R.id.SeriesMainListItemView); LayoutInflater mInflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE); for (int i=0; i<scheduleArr.length; i++) { View inflatedView = mInflater.inflate(R.layout.scheduleitem, null); TextView inflatertext1 = (TextView) inflatedView.findViewById(R.id.text1); TextView inflatertext2 = (TextView) inflatedView.findViewById(R.id.text2); inflatertext1.setText(scheduleArr[i][0]); inflatertext2.setText(scheduleArr[i][1]); Log.i("data",i + " " + scheduleArr[i][0] + "/" + scheduleArr[i][1]); seriesMainListItemView.addView(inflatedView); } 

Here is the xml that I want to add several times.


Here is LinearLayout where I want to add it.

 <TableLayout android:layout_gravity="center_vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" android:paddingLeft="1dip" android:paddingRight="1dip" > <TableRow android:layout_width="fill_parent" android:layout_height="fill_parent"> <ImageView android:id="@+id/imgSeriesMainScheduleImg" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" android:background="@drawable/scheduleheader"/> <LinearLayout android:id="@+id/SeriesMainListItemView" android:layout_width="fill_parent" android:layout_height="fill_parent"> </LinearLayout> </TableRow> .............. </TableLayout> 

But only one view is added to LinearLayout, although the length of the array is 3. What is the problem in my code?

+8
android view android-linearlayout
source share
2 answers

I added the LinearLayout orientation as vertical. And it becomes perfect. Thanks Sujit for your hints.

+11
source share

Use the addView() version that accepts the LayoutParams object, put the appropriate LinearLayout.LayoutParams and see if that helps.

0
source share

All Articles