Note that there are some explanatory texts on larger screens.

plurals
  1. POShowing two fragments for an ActionBar Tab
    primarykey
    data
    text
    <p>I used the Eclipse project wizard to create a project with an ActionBar and tabs. The wizard creates a dummy fragment for each tab with dummy text just showing the tab number. The app works without problems.</p> <p>The code looks like this:</p> <pre><code> @Override public void onTabSelected(ActionBar.Tab tab, FragmentTransaction fragmentTransaction) { // When the given tab is selected, show the tab contents in the container Fragment fragment = new DummySectionFragment(); Bundle args = new Bundle(); args.putInt(DummySectionFragment.ARG_SECTION_NUMBER, tab.getPosition() + 1); fragment.setArguments(args); getFragmentManager().beginTransaction() .replace(R.id.container, fragment) .commit(); } /** * A dummy fragment representing a section of the app, but that simply displays dummy text. */ public static class DummySectionFragment extends Fragment { public DummySectionFragment() { } public static final String ARG_SECTION_NUMBER = "section_number"; @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { TextView textView = new TextView(getActivity()); textView.setGravity(Gravity.CENTER); Bundle args = getArguments(); textView.setText(Integer.toString(args.getInt(ARG_SECTION_NUMBER))); return textView; } } </code></pre> <p>For the purpose of my App I would like to show one fragment when the device is in portrait mode and two fragments when the device is in landscape mode. I know about the Shakespeare sample but in this sample it is an activity the holds the one or two fragments. </p> <p>The Shakespeare sample uses two different layouts. For portrait mode (in "layout\fragment_layout_support.xml"):</p> <pre><code>&lt;FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent"&gt; &lt;fragment class=".FragmentLayoutSupport$TitlesFragment" android:id="@+id/titles" android:layout_width="match_parent" android:layout_height="match_parent" /&gt; &lt;/FrameLayout&gt; </code></pre> <p>and for landscape mode (in "layout-land\fragment_layout_support.xml"):</p> <pre><code>&lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="horizontal" android:layout_width="match_parent" android:layout_height="match_parent"&gt; &lt;fragment class=".FragmentLayoutSupport$TitlesFragment" android:id="@+id/titles" android:layout_weight="1" android:layout_width="0px" android:layout_height="match_parent" /&gt; &lt;FrameLayout android:id="@+id/details" android:layout_weight="1" android:layout_width="0px" android:layout_height="match_parent" /&gt; &lt;/LinearLayout&gt; </code></pre> <p>The Shakespeare sample loads the layout like this: </p> <pre><code>public class FragmentLayoutSupport extends FragmentActivity { @Override protected void onCreate(Bundle savedInstanceState) { //setTheme(SampleList.THEME); //Used for theme switching in samples super.onCreate(savedInstanceState); setContentView(R.layout.fragment_layout_support); } ... </code></pre> <p>How do I do the same for my App where I cannot load the layout in a FragmentActivity?</p> <p>Thanks. </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.
 

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