Note that there are some explanatory texts on larger screens.

plurals
  1. POCall onStart() of Fragment before to display Viewpager, navigation_mode_tabs
    primarykey
    data
    text
    <p>I used a ViewPager and an ActionBar with NavigationMode : "NAVIGATION_MODE_TABS"</p> <p>I put 3 Fragments : Fragment0 (left tab) ,Fragment1 (middle tab),Fragment2(right tab)</p> <p>First, the Fragment0 appears and the methods "onCreateView" and "onStart" are called for Fragment0 AND the Fragment1 </p> <p>If I slide horizontally to go to the "middle tab"(Fragment1), the methods "onCreateView" and "onStart" of Fragment2(right tab) are called...</p> <p>So, I want to know if this is normal ?</p> <p>Because I want to call "onStart" of Fragment2 just before it appears, How do it?</p> <p>My code : </p> <pre><code>public class ActivityPrincipale extends FragmentActivity { private Intent intentService1; private Fragment fragment; [..] private ActionBar.TabListener tabListener; @Override protected void onCreate(Bundle arg0) { super.onCreate(arg0); setContentView(R.layout.viewpager); // Création de la liste de Fragments que fera défiler le PagerAdapter listFragments = new Vector(); // Ajout des Fragments dans la liste des fragments listFragments.add(Fragment.instantiate(this, Fragment0.class.getName())); listFragments.add(Fragment.instantiate(this, Fragment1.class.getName())); listFragments.add(Fragment.instantiate(this, Fragment2.class.getName())); // Création de l'adapter qui s'occupera de l'affichage de la liste de Fragments this.mPagerAdapter = new MyPagerAdapter(super.getSupportFragmentManager(), listFragments); pagerView = (ViewPager) super.findViewById(R.id.viewpager); // affectation de l'adapter au ViewPager pagerView.setAdapter(this.mPagerAdapter); pagerView.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() { @Override public void onPageSelected(int position) { // Quand il y a un swapp entre les page // on selectionne le tab correspondant Log.w("SWAPPING FRAGMENT!!", "swapping de fragment avec comme positin de destination = " + position); getActionBar().setSelectedNavigationItem(position); // DEBUGMODE } }); actionBar = getActionBar(); actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); // Create a tab listener that is called when the user changes tabs. tabListener = new ActionBar.TabListener() { public void onTabSelected(ActionBar.Tab tab, FragmentTransaction ft) { pagerView.setCurrentItem(tab.getPosition()); } public void onTabUnselected(ActionBar.Tab tab, FragmentTransaction ft) { } public void onTabReselected(ActionBar.Tab tab, FragmentTransaction ft) { } }; actionBar.addTab(actionBar.newTab().setText("Frag0").setTabListener(tabListener)); actionBar.addTab(actionBar.newTab().setText("Frag1"").setTabListener(tabListener)); actionBar.addTab(actionBar.newTab().setText("Frag2").setTabListener(tabListener)); } } </code></pre> <p>One Fragment :</p> <pre><code>public class Fragment0 extends Fragment { @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.fragment_0, container, false); Log.w("oFragmento", "fragment0"); return rootView; } } </code></pre> <p>My PagerAdapter :</p> <pre><code>public class MyPagerAdapter extends FragmentPagerAdapter { private final List fragments; public MyPagerAdapter(FragmentManager fm, List list_fragments) { super(fm); this.fragments = list_fragments; } @Override public Fragment getItem(int position) { return (Fragment) fragments.get(position); } @Override public int getCount() { return this.fragments.size(); } } </code></pre>
    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.
    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