Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package yuvallevy.testrecyclerview;
- import android.support.v4.app.Fragment;
- import android.support.v4.app.FragmentManager;
- import android.support.v4.app.FragmentStatePagerAdapter;
- import java.util.ArrayList;
- import java.util.List;
- import yuvallevy.testrecyclerview.Interfaces.Tab1MainFragmentListner;
- public class MyPagerAdapter extends FragmentStatePagerAdapter {
- private List<Fragment> fragmentList = new ArrayList<>();
- private List<String> fragmentTitleList = new ArrayList<>();
- private Fragment mFragmentAtPos0;
- private FragmentManager mFragmentManger;
- static final int NUM_ITEMS = 3;
- public MyPagerAdapter(FragmentManager fm) {
- super(fm);
- }
- @Override
- public Fragment getItem(int pos) {
- if(pos == 0){
- if(mFragmentAtPos0 == null){
- return mFragmentAtPos0 = Tab1MainView.newInstance();
- }else{
- return mFragmentAtPos0;
- }
- }else {
- return fragmentList.get(pos);
- }
- }
- @Override
- public int getItemPosition(Object object) {
- if(object instanceof CategorySelected){
- return POSITION_NONE;
- }else if(object instanceof Tab1Fragment){
- return POSITION_NONE;
- }else {
- return POSITION_UNCHANGED;
- }
- }
- @Override
- public int getCount() {
- return NUM_ITEMS;
- }
- @Override
- public CharSequence getPageTitle(int position) {
- return fragmentTitleList.get(position);
- }
- public void addFragment(Fragment fragment, String title){
- fragmentList.add(fragment);
- fragmentTitleList.add(title);
- }
- public final class Tab1Fragment implements Tab1MainFragmentListner{
- @Override
- public void onSwitchToNextFragment(int pos) {
- mFragmentManger.beginTransaction().remove(mFragmentAtPos0).commit();
- mFragmentAtPos0 = CategorySelected.newInstance(pos);
- notifyDataSetChanged();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement