Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I know its too late.But it will help some others. Use show and hide instead of replace.Here is a sample code.</p> <pre><code>private class MyTabListener implements ActionBar.TabListener { @Override public void onTabSelected(Tab tab, FragmentTransaction ft) { switch (tab.getPosition()) { case 0: if (frag1 == null) { // If not, instantiate and add it to the activity frag1 = Fragment.instantiate(getApplicationContext(), FeedsActivity.class.getName()); ft.add(android.R.id.content, frag1, "Feeds"); } else { // If it exists, simply attach it in order to show it ft.show(frag1); } return; case 1: if (frag2 == null) { // If not, instantiate and add it to the activity frag2 = Fragment.instantiate(getApplicationContext(), ProfileActivity.class.getName()); ft.add(android.R.id.content, frag2, "Profile"); } else { // If it exists, simply attach it in order to show it ft.show(frag2); } return; case 2: if (frag3 == null) { // If not, instantiate and add it to the activity frag3 = Fragment.instantiate(getApplicationContext(), History.class.getName()); ft.add(android.R.id.content, frag3, "History"); } else { // If it exists, simply attach it in order to show it ft.show(frag3); } return; } } @Override public void onTabUnselected(Tab tab, FragmentTransaction ft) { // TODO Auto-generated method stub if (frag1 != null) { // Detach the fragment, because another one is being attached switch (tab.getPosition()) { case 0: ft.hide(frag1); return; case 1: ft.hide(frag2); return; case 2: ft.hide(frag3); return; } } } @Override public void onTabReselected(Tab tab, FragmentTransaction ft) { // TODO Auto-generated method stub } } </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