Note that there are some explanatory texts on larger screens.

plurals
  1. POsetRetainInstance(true); doing it wrong?
    primarykey
    data
    text
    <p>I think an illustration of what happens in my app is best for this question.</p> <p>After the user logs in they are brought to the MainActivity. This contains an <code>ActionBar</code> with tabs, by default one tab is selected and the user sees....</p> <pre><code> container1 container2 CompanyName: &lt;EditText&gt; | | ProjectName: &lt;EditText&gt; | Welcome | &lt;SearchButton&gt; | | </code></pre> <p>When the user fills out those forms and clicks the search button they see...</p> <pre><code> container1 container2 &lt;ListView&gt; | | BasicInfo | Welcome | Assessment | | Signature | | </code></pre> <p>When the user clicks "Assesment" they see</p> <pre><code> container1 container2 &lt;ListView&gt; | Question#1 | BasicInfo | Question#2 | Assessment | Question#3 | Signature | Question#4 | </code></pre> <p>Now when the Assessment <code>fragment</code> inflates it performs an <code>AsyncTask</code> and creates the <code>Views</code> for the questions from <code>JSON</code>. Now when the user is on this screen I do not want a screen orientation change to perform the network request and <code>AsyncTask</code> again. So I put the <code>setRetainInstance(true);</code> in the Assessment <code>Fragment</code> like this</p> <pre><code>public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { view = inflater.inflate(R.layout.fragment_assessment, container, false); ab = getActivity().getActionBar(); infoList = new ArrayList&lt;HashMap&lt;String, String&gt;&gt;(); allRadio = new ArrayList&lt;RadioGroup&gt;(); allImageButton = new ArrayList&lt;ImageButton&gt;(); allSpinner = new ArrayList&lt;Spinner&gt;(); allEdit = new ArrayList&lt;EditText&gt;(); allCheck = new ArrayList&lt;CheckBox&gt;(); new Load().execute(); setRetainInstance(true); return view; } </code></pre> <p>Yet when I flip my screen in the Assessment <code>Fragment</code> not only does it not save the layout it returns me to the parent <code>Activity</code> that looks like this</p> <pre><code> container1 container2 CompanyName: &lt;EditText&gt; | | ProjectName: &lt;EditText&gt; | Welcome | &lt;SearchButton&gt; | | </code></pre> <p>Not sure what I'm doing wrong. It could be my <code>fragment</code> in <code>XML</code> is named incorrectly or maybe the containers are named incorrectly. Here is there code.</p> <p><strong>Container XML</strong></p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/MainLayout" android:layout_width="match_parent" android:layout_height="match_parent" android:baselineAligned="false" android:orientation="horizontal" &gt; &lt;LinearLayout android:id="@+id/header_fragment_container" android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1.2" android:background="@drawable/green_gradient" android:orientation="vertical" &gt; &lt;/LinearLayout&gt; &lt;LinearLayout android:id="@+id/content_fragment_container" android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="2" android:background="@drawable/twoglobe_line" android:orientation="vertical" android:scrollbars="vertical" &gt; &lt;/LinearLayout&gt; &lt;/LinearLayout&gt; </code></pre> <p><strong>Assessment Fragment XML</strong></p> <pre><code>&lt;ScrollView xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/basic_info_scroll" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@drawable/twoglobe_line" android:gravity="center" android:orientation="vertical" &gt; &lt;LinearLayout android:id="@+id/gen_layout" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginLeft="15dp" android:layout_marginRight="15dp" android:layout_marginTop="10dp" android:gravity="center" android:orientation="vertical" &gt; &lt;LinearLayout android:id="@+id/add" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginLeft="5dp" android:layout_marginRight="5dp" android:layout_marginTop="10dp" android:orientation="vertical" &gt; &lt;/LinearLayout&gt; &lt;/LinearLayout&gt; &lt;/ScrollView&gt; </code></pre> <p>So am I expecting an unrealistic outcome from the line <code>setRetainInstance(true);</code> or am I just doing it wrong? Any help is appreciated.</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.
 

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