Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Eureka! My solution is to provide an alternate layout for the Details Activity that was empty. After I inflate the layout I can check to see if the fragment I am expecting is in the layout and if it isn't then I finish().</p> <p>details_view.xml in /res/layout:</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;fragment android:name="com.website.DetailsFragment" android:layout_width="0dp" android:layout_height="match_parent" android:id="@+id/details_fragment" android:layout_weight="75"&gt; &lt;/fragment&gt; &lt;/LinearLayout&gt; </code></pre> <p>details_view.xml in /res/layout-[screen size] This one is for any screen size that you do not want to display the Details fragment in its own activity in landscape mode (more or less tablets in my case).</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;!-- Note: This file has an empty layout to notify DetailsViewActivity that we should go back to landscape and view the fragments side by side --&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;/LinearLayout&gt; </code></pre> <p>Simply put the empty details_view.xml file in any layout directory that has the layout file that allows to show the fragments side by side.</p> <p>Finally the code for DetailsViewActivity to exit if we want to go back to side by side:</p> <pre><code>public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.details_view); mDetailsView = (TopicViewFragment)getSupportFragmentManager() .findFragmentById(R.id.details_fragment); // We can handle the fragments side by side in the previous activity // so lets go back there if ((mDetailsView == null || !mDetailsView.isInLayout()) &amp;&amp; getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) { finish(); return; } </code></pre> <p>I would have liked a little less duplication of data but this solution isn't bad. It only forces you to copy one extra layout file into the same directory that you have the side by side fragments layout file. Not too bad really.</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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. 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