Note that there are some explanatory texts on larger screens.

plurals
  1. POHow can I declare a Fragment as hidden in an XML layout
    primarykey
    data
    text
    <p>My activity declares all of its GUI fragments in a single XML layout. It only needs to display a few of the fragments at launch time; the rest get shown as the user interacts with the app. A portion of the layout is as follows:</p> <pre><code>&lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" &gt; &lt;fragment android:id="@+id/map_panel" android:name="com.example.MapPanel" android:layout_width="match_parent" android:layout_height="@dimen/map_panel_height" /&gt; &lt;fragment android:id="@+id/list_panel" android:name="com.example.ListPanel" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_below="@+id/map_panel" /&gt; &lt;fragment android:id="@+id/detail_panel" android:name="com.example.DetailPanel" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_below="@+id/map_panel" android:visibility="gone" /&gt; </code></pre> <p>My intention is that the <code>list_panel</code> fragment is visible at startup, and the <code>detail_panel</code> fragment is hidden until the user selects something from the list.</p> <p>By default, a fragment starts out with the <code>isHidden</code> attribute as false. That means my activity has to iterate through the loaded fragments and manually call <code>isHidden(true)</code> on fragments like <code>detail_panel</code> at startup time. </p> <p>I would prefer to declare the <code>isHidden</code> status in the XML layout. However, setting <code>android:visibility="gone"</code> in a <code>&lt;fragment&gt;</code> declaration does not change the <code>isHidden</code> status, and I can't find any documentation on another attribute that would do the trick.</p> <p>Is it possible to set an XML attribute on a <code>&lt;fragment&gt;</code> to cause it to be hidden?</p> <p>Note: I'm not concerned with view visibility, I'm concerned with the <code>fragment.isHidden()</code> value. That affects how FragmentManager manipulates the back stack and performs animations. If you call <code>transaction.show(fragment)</code> on a fragment whose view is invisible or gone, but the <code>fragment.isHidden()</code> value is false, then the FragmentManager will not make the view visible. See <a href="http://developer.android.com/reference/android/app/Fragment.html#isHidden()">http://developer.android.com/reference/android/app/Fragment.html#isHidden()</a> for reference.</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