I'm creating an app with an actionBar with tabs. I would like it so that when you select a tab, a specific fragment is called. I have a problem where when the app is created, two fragments are immediately called when only one should be called. My code regarding that is as follows:
@Override
public Fragment getItem(int index)
{
switch (index)
{
final String TAG0 = "MainActivity";
Log.wtf(TAG0, "fragA active");
case 0:
return new FragA();
final String TAG1 = "MainActivity";
Log.wtf(TAG1, "fragB active");
case 1:
return new fragB();
final String TAG2 = "MainActivity";
Log.wtf(TAG2, "fragC active");
case 2:
return new fragC();
}
return null;
}
The actionBar's tabs are set up so that tabA opens fragA, tabB for fragB, etc. Now when the app is created, the log messages i'm getting show fragA active and fragB active although only tabA is selected. When tabB is selected, fragC becomes active. when tabC is selected, nothing happens. When you go to select any other tab after this, I'm getting no additional log messages.
The second situation is when the app starts, fragA and fragB are active although only tabA is selected. When you click tabC, fragC now becomes active. When you click any other tab after this, nothing happens and I receive no additional log messages.
Also, I think it's worth noting I've tried adding in break statements in each case within the switch statement. When I have a break statement for cases 0, 1, and 2, the break statements for cases 1 and 2 are fine, but the break statement for case 0 shows that is an unreachable statement.
If you need any additional code from me, please let me know. Thank you for your help.