Note that there are some explanatory texts on larger screens.

plurals
  1. POInflating GUI works only once, how come?
    primarykey
    data
    text
    <p>I'm new to Android development.</p> <p>I have Activity, to which I wish to add some GUI-elements.</p> <pre><code>@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_dial_details); if (android.os.Build.VERSION.SDK_INT &gt;= 11) // Show the Up button in the action bar. getActionBar().setDisplayHomeAsUpEnabled(true); inflateNewRow(); inflateNewRow(); } private void inflateNewRow() { LinearLayout thisLayout = (LinearLayout) findViewById(R.id.dial_details_layout); LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE); // Before edit! //inflater.inflate(R.layout.dialitem_details, thisLayout); // After edit, which works! inflater.inflate(R.layout.dialitem_details, null); thisLayout.addView(ll); } </code></pre> <p>The first call to inflateNewRow adds the row, fine. The second call, seems to do nothing! No exception, no row is added.</p> <p>I added the setVisibility call, just to make sure. It makes no difference.</p> <p>It might seem strange to call inflateNewRow twice, but it's actually just for this example. It is to be called once in the onCreate, then from a menus click-event. This simple example recreates the problem though.</p> <p>This is the little view that's to be added:</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="match_parent" android:orientation="horizontal" &gt; &lt;EditText android:id="@+id/editText1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="2" android:ems="10" android:inputType="number" &gt; &lt;requestFocus /&gt; &lt;/EditText&gt; &lt;CheckBox android:id="@+id/checkBox1" android:layout_width="wrap_content" android:layout_height="wrap_content" /&gt; &lt;/LinearLayout&gt; </code></pre> <p>into this:</p> <pre><code>&lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/dial_details_layout" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" tools:context=".DialDetailsActivity" &gt; &lt;CheckBox android:id="@+id/checkBox1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="CheckBox" /&gt; &lt;EditText android:id="@+id/editText1" android:layout_width="match_parent" android:layout_height="wrap_content" android:ems="10" android:inputType="number" &gt; &lt;requestFocus /&gt; &lt;/EditText&gt; &lt;/LinearLayout&gt; </code></pre> <p>Any ideas why only the first row appears / is added?</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.
 

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