Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid container programmatically
    text
    copied!<p>I am performing an HTTP request and getting results. Then I want to scroll through these results and create the following for each result: (RL = Relative Layout)</p> <p><img src="https://i.stack.imgur.com/lxbhp.png" alt="enter image description here"></p> <p>A Relative Layout (RL in the pic) with a TextView and an ImageView on the inside. I then want to add all of these 'containers' to a List and pass them off for interpretation.</p> <pre><code>//inside onPostExecute - given a list List&lt;RelativeLayout&gt; containers = new ArrayList&lt;RelativeLayout&gt;(); for(i=0; i&lt;alist.size();i++){ RelativeLayout newLayout = new RelativeLayout(getApplicationContext()); TextView tv = new TextView(getApplicationContext()); ImageView iv = new ImageView(getApplicationContext()); newLayout.addView(tv); newLayout.addView(iv); containers.add(newLayout); } otherClass.send(containers); </code></pre> <p>I essentially want to programmatically create a container, put two things in it, and send it off for further processing. </p> <p>(Is this possible, or is there a better way to do this?) *EDITED</p> <p>Thanks in advance for any help, I have spent a lot of time on this already</p> <hr> <p>*I have tried this, it throws an exception when trying to pass the list of layouts I think</p> <hr> <p>Just going to add more here:</p> <pre><code>public void send(List&lt;RelativeLayout&gt; containers) { for(int i=0; i&lt;containers.size(); i++){ RelativeLayout rl = new RelativeLayout(mContext); rl = containers.get(i); icons_row.addView(rl); } } </code></pre> <p>And the exception</p> <pre><code>03-29 10:20:32.290: E/AndroidRuntime(29782): FATAL EXCEPTION: main 03-29 10:20:32.290: E/AndroidRuntime(29782): java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first. 03-29 10:20:32.290: E/AndroidRuntime(29782): at android.view.ViewGroup.addViewInner(ViewGroup.java:3618) 03-29 10:20:32.290: E/AndroidRuntime(29782): at android.view.ViewGroup.addView(ViewGroup.java:3489) 03-29 10:20:32.290: E/AndroidRuntime(29782): at android.view.ViewGroup.addView(ViewGroup.java:3434) 03-29 10:20:32.290: E/AndroidRuntime(29782): at android.view.ViewGroup.addView(ViewGroup.java:3410) </code></pre>
 

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