Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You'll need to invoke <code>addView()</code> on the primary layout. Once the primary layout is built (which holds all the other layouts), the <code>addView()</code> method will add new views to the existing primary layout.</p> <p>To add the new layout, you'll need to inflate it first.</p> <pre><code>LinearLayout primaryLayout; LayoutInflater layoutInflater = (LayoutInflater)this.getSystemService( Context.LAYOUT_INFLATER_SERVICE ); LinearLayout newLayout = (LinearLayout)layoutInflater.inflate(R.layout.your_new_layout, null, false); primaryLayout.addView(newLayout); </code></pre> <p>AddView also provides an index option to place the new layout at a specific point in the primary layout.</p> <p>Try starting with a blank, XML layout (say called primary_layout):</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/primaryLayout" android:layout_width="match_parent" android:layout_height="match_parent" &gt; &lt;/RelativeLayout&gt; </code></pre> <p>Then, as your activity starts, set that first, then inflate and add as desired:</p> <pre><code>setContentView(R.layout.primary_layout); LinearLayout primaryLayout = (LinearLayout) findViewById(R.id.primaryLayout); </code></pre> <p>Then you can add your new views to that one. As for adding multiple times, I believe that it's done by reference, so it only sees a single view. Try building the view in a method, and just returning the view. Such as:</p> <pre><code>private View buildNewView(){ LayoutInflater layoutInflater = (LayoutInflater)this.getSystemService( Context.LAYOUT_INFLATER_SERVICE ); LinearLayout newView = (LinearLayout)layoutInflater.inflate( R.layout.my_new_view null, false ); return newView ; } </code></pre> <p>And call it via <code>primaryLayout.addView(buildNewView();</code>.</p>
    singulars
    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.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      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