Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class CustomPagerAdapter extends PagerAdapter {
- private Context mContext;
- public CustomPagerAdapter(Context context) {
- mContext = context;
- }
- @Override
- public Object instantiateItem(ViewGroup collection, int position) {
- BottomNavigationModel modelObject = BottomNavigationModel.values()[position];
- LayoutInflater inflater = LayoutInflater.from(mContext);
- ViewGroup layout = (ViewGroup) inflater.inflate(modelObject.getLayoutResId(), collection, false);
- collection.addView(layout);
- return layout;
- }
- @Override
- public void destroyItem(ViewGroup collection, int position, Object view) {
- collection.removeView((View) view);
- }
- @Override
- public int getCount() {
- return BottomNavigationModel.values().length;
- }
- @Override
- public boolean isViewFromObject(View view, Object object) {
- return view == object;
- }
- @Override
- public CharSequence getPageTitle(int position) {
- BottomNavigationModel customPagerEnum = BottomNavigationModel.values()[position];
- return mContext.getString(customPagerEnum.getTitleResId());
- }
- }
- viewPager.setAdapter(new CustomPagerAdapter(this));
- viewPager.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View view) {
- // Not calling this one TODO here
- }
- });
- public enum BottomNavigationModel {
- ONE(R.string.page_one, R.layout.view_row_one),
- TWO(R.string.page_two, R.layout.view_row_two),
- THREE(R.string.page_three, R.layout.view_row_three);
- private int mTitleResId;
- private int mLayoutResId;
- BottomNavigationModel(int titleResId, int layoutResId) {
- mTitleResId = titleResId;
- mLayoutResId = layoutResId;
- }
- public int getTitleResId() {
- return mTitleResId;
- }
- public int getLayoutResId() {
- return mLayoutResId;
- }
- }
- @Override
- public Fragment getItem(int position) {
- switch (position) {
- case 0:
- return new DescriptionFragment();
- case 1:
- return new ReviewFragment();
- case 3:
- return new OrderFragment();
- default:
- return null;
- }
- }
Add Comment
Please, Sign In to add comment