Note that there are some explanatory texts on larger screens.

plurals
  1. POandroid how to press a tab in FragmentTabHost to get to FragmentActivity instead of another Fragment
    text
    copied!<p>I want to make an app with 3 tabs at the bottom. in my app I want that each tab click will open another FragmentActivity that will have a ViewPager, so i can swipe Activities with my finger but still remains in the same tab. right now, each tab just open a Fragment so i cant use view pager. how do i open a fragment activity from FragmentTabHost? this is my code, thanks!</p> <pre><code>public class MainActivity extends FragmentActivity { private FragmentTabHost mTabHost; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.bottom_tabs); mTabHost = (FragmentTabHost) findViewById(android.R.id.tabhost); mTabHost.setup(this, getSupportFragmentManager(), R.id.realtabcontent); Bundle b = new Bundle(); b.putString("key", "one"); mTabHost.addTab(mTabHost.newTabSpec("one").setIndicator("one"), Fragment1.class, b); // b = new Bundle(); b.putString("key", "two"); mTabHost.addTab(mTabHost.newTabSpec("two") .setIndicator("two"), Fragment2.class, b); b = new Bundle(); b.putString("key", "three"); mTabHost.addTab(mTabHost.newTabSpec("three").setIndicator("three"), Fragment3.class, b); } </code></pre> <p>this is just a Fragment example</p> <pre><code> public class Fragment1 extends Fragment { private TextView text; public Fragment1() { // TODO Auto-generated constructor stub } @Override public void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); } @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // TODO Auto-generated method stub View v = LayoutInflater.from(getActivity()).inflate(R.layout.layout, null); text = (TextView) v.findViewById(R.id.text); if (getArguments() != null) { // try { String value = getArguments().getString("key"); text.setText("THIS IS THE FIRST TAB - " + value); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } return v; } @Override public void onActivityCreated(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onActivityCreated(savedInstanceState); } // } </code></pre> <p>and this is the XML </p> <pre><code>&lt;FrameLayout android:id="@+id/realtabcontent" android:layout_width="match_parent" android:layout_height="0dip" android:layout_weight="1" &gt; &lt;/FrameLayout&gt; &lt;android.support.v4.app.FragmentTabHost android:id="@android:id/tabhost" android:background="@android:color/darker_gray" android:layout_width="match_parent" android:layout_height="wrap_content" &gt; &lt;FrameLayout android:id="@android:id/tabcontent" android:layout_width="0dp" android:layout_height="0dp" android:layout_weight="0" /&gt; &lt;/android.support.v4.app.FragmentTabHost&gt; </code></pre>
 

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