I'm crating a tabHost to contain all the content of my Android application in 3 tabs, should i create the content of the tab inside its linear layout or create the tab content in a separate fragment and include it in the tab layout? And how to include the fragment inside a layout also? Excuse me i'm a bit beginner to this.
Asked
Active
Viewed 111 times
0
-
tab host is kind of silently deprecated. probably not what you want to do. look into viewpager. this might help http://developer.android.com/training/implementing-navigation/lateral.html – dabluck Apr 27 '15 at 02:13
-
Saw an answer here just telling the opposite, had me using the tabHost over the veiwPager! – ahmed mostafa Apr 27 '15 at 02:21
-
that's weird. I can't imagine anyone recommending a tab host in 2015. – dabluck Apr 27 '15 at 02:21
1 Answers
0
you just add viewpagger for calling fragment
public class MyPagerAdapter extends FragmentPagerAdapter {
private final String[] TITLES = { "Fragment1", "Fragment2", "Fragment2" };
public MyPagerAdapter(FragmentManager fm) {
super(fm);
}
@Override
public CharSequence getPageTitle(int position) {
return TITLES[position];
}
@Override
public int getCount() {
return TITLES.length;
}
@Override
public Fragment getItem(int position) {
//return SuperAwesomeCardFragment.newInstance(position);
switch (position) {
case 0:
return new JavaFragment1(); //this call you fragment1
case 1:
return new JavaFragment2(); //this call you fragment2
case 2:
return new JavaFragment3(); //this call you fragment3
}
return null;
}
}

Newbies
- 1,394
- 1
- 11
- 3