Created
April 8, 2019 08:19
-
-
Save sbis04/2f04dd30e12c7291cfdab6c1251bfa1a to your computer and use it in GitHub Desktop.
Using Tabbed Layout and View Pager
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import android.content.Context; | |
import android.support.v4.app.Fragment; | |
import android.support.v4.app.FragmentManager; | |
import android.support.v4.app.FragmentPagerAdapter; | |
public class CategoryAdapter extends FragmentPagerAdapter { | |
private Context mContext; | |
public CategoryAdapter(Context context, FragmentManager fm) { | |
super(fm); | |
mContext = context; | |
} | |
@Override | |
public Fragment getItem(int position) { | |
if (position == 0) { | |
return new NumbersFragment(); | |
} else if (position == 1) { | |
return new FamilyFragment(); | |
} else if (position == 2) { | |
return new ColorsFragment(); | |
} else { | |
return new PhrasesFragment(); | |
} | |
} | |
@Override | |
public int getCount() { | |
return 4; | |
} | |
@Override | |
public CharSequence getPageTitle(int position) { | |
if (position == 0) { | |
return mContext.getString(R.string.category_numbers); | |
} else if (position == 1) { | |
return mContext.getString(R.string.category_family); | |
} else if (position == 2) { | |
return mContext.getString(R.string.category_colors); | |
} else { | |
return mContext.getString(R.string.category_phrases); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment