Note that there are some explanatory texts on larger screens.

plurals
  1. PODynamic layout inflator within a loop
    primarykey
    data
    text
    <p>I want to display <em>x</em> number of an xml layout within an activity based upon a loop of data from a parcelable array. For this example, I've changed the array size to a fixed value of 3.</p> <p>The xml of the layout I am wanting to inflate is:</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical" &gt; &lt;TextView android:id="@+id/tv_title" android:layout_width="wrap_content" android:layout_height="wrap_content"/&gt; &lt;RadioGroup android:id="@+id/rg_type" android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="horizontal"&gt; &lt;RadioButton android:id="@+id/radioButton1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Yes" android:tag="1" /&gt; &lt;RadioButton android:id="@+id/radioButton2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="No" android:tag="0" /&gt; &lt;RadioButton android:id="@+id/radioButton3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Don't Know" android:tag="3" /&gt; &lt;/RadioGroup&gt; &lt;/LinearLayout&gt; </code></pre> <p>The xml of the parent page is:</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical"&gt; &lt;LinearLayout android:id="@+id/ll_content" android:layout_width="fill_parent" android:layout_height="wrap_content"&gt; &lt;/LinearLayout&gt; &lt;/LinearLayout&gt; </code></pre> <p>This is the code for the Activity:</p> <pre><code>public class PainRecord_FollowUp extends Activity { LinearLayout llContent; Context context; PainDataItem pd_in; //this is the Parcelable extra received /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.painrecord_followup); Bundle extras = getIntent().getExtras(); if (extras != null) { pd_in = extras.getParcelable("m_PainDataItem"); } LayoutInflater layoutInflator = (LayoutInflater) getApplicationContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE); LinearLayout insertPoint = (LinearLayout) findViewById(R.id.ll_content); List views = new ArrayList(); for(int i=0; i&lt;3; i++){ View view = layoutInflator.inflate(R.layout.row_painrecord_followup, null); TextView textView = (TextView) view.findViewById(R.id.tv_title); textView.setText("did x help " + i); view.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); views.add(view); } for(int i = 0; i&lt;views.size(); i++) insertPoint.addView((View) views.get(i)); } } </code></pre> <p>Instead of showing each layout underneath each other, it displays it like this:</p> <p><img src="https://i.stack.imgur.com/Jy9BM.gif" alt="enter image description here"></p> <p>If I change to LayoutParams.FILL_PARENT, then just the [0] loop value shows.</p> <p>Any advice greatly received.</p> <p>Thanks</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload