2

I have a fragment that loads two other fragments as :

SoccerFragment loads -> MatchFragment,VoteFragment.

When first time the SoccerFragment is created i can refresh the twofragments and get the data in MatchFragment and VoteFragment successfully.

The problem is when switching between other fragments and going back to the SoccerFragment which is holding the two fragments i am not able to refresh the two fragments inside as below :

enter image description here

i have searched and found some solutions but didn t work as :

1- Deriving my class ViewPagerAdapter from FragmentpagerAdapter to extending FragmentStatePagerAdapter.

2- viewpager.setOffscreenPageLimit(0);

This is my SoccerFragment class :

public class SoccerFragment extends Fragment {


    public CoordinatorLayout coordinatorLayout;
    public boolean isConnected;
    public ViewPager viewPager;
    public TabLayout tabLayout;
    public String id, name_team1, name_team2;

    @Override
    public void onPrepareOptionsMenu(Menu menu) {

        super.onPrepareOptionsMenu(menu);
    }


    public SoccerFragment() {
        // Required empty public constructor
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        View v = inflater.inflate(R.layout.fragment_soccer, null);
        viewPager = (ViewPager) v.findViewById(R.id.viewpager2);
        addTabs(viewPager);
        tabLayout = (TabLayout) v.findViewById(R.id.tabs2);
        tabLayout.setupWithViewPager(viewPager);




        return v;
    }

    private void addTabs(ViewPager viewPager) {

        ViewPagerAdapter adapter = new ViewPagerAdapter(getActivity().getSupportFragmentManager());
        adapter.addFrag(new ThreeFragment(),"المباريات");
        adapter.addFrag(new VoteFragment(),"التصويت");
        viewPager.setOffscreenPageLimit(0);

        viewPager.setAdapter(adapter);
    }




    class ViewPagerAdapter extends FragmentStatePagerAdapter {
        private final List<Fragment> mFragmentList = new ArrayList<>();
        private final List<String> mFragmentTitleList = new ArrayList<>();

        public ViewPagerAdapter(FragmentManager manager) {
            super(manager);
        }

        @Override
        public Fragment getItem(int position) {
            return mFragmentList.get(position);
        }

        @Override
        public int getCount() {
            return mFragmentList.size();
        }

        public void addFrag(Fragment fragment, String title) {
            mFragmentList.add(fragment);
            mFragmentTitleList.add(title);
        }

        @Override
        public CharSequence getPageTitle(int position) {
            return mFragmentTitleList.get(position);
        }
    }

    @Override
    public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
        inflater.inflate(R.menu.menu_main, menu);


        super.onCreateOptionsMenu(menu, inflater);
    }
}

What should i do ?

EDITED : this is the code of one of my two fragments inside the SoccerFragment:

public class VoteFragment extends Fragment  implements ConnectivityReceiver.ConnectivityReceiverListener,
        SwipeRefreshLayout.OnRefreshListener {
    public LinearLayout coordinatorLayout;
    public boolean isConnected;
    public PostAdapter6 adapter;
    public RecyclerView recycler_vote;
    ArrayList<Vote_valid_data> post_array = new ArrayList<>();
    public SwipeRefreshLayout swipeRefreshLayout;
    public String id, st_image1, st_image2, st_team1, st_team2, stadium, tour, name_match,id_signin;
    ImageView image1, image2;
    public TextView name_team1, name_team2, between, between1, txt_team1, txt_team2;
    public Button bt_increment1, bt_deincrement1, bt_increment2, bt_deincrement2, bt_tosignin;
    public int calcul, calcul1 = 0, i = 0;
    public String fb_email, fb_name,fb_image;
    public Switch aSwitch2;


    public VoteFragment() {
        // Required empty public constructor
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        int id = item.getItemId();


        return super.onOptionsItemSelected(item);
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setHasOptionsMenu(true);
        checkConnectivity();

    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        View v = inflater.inflate(R.layout.fragment_vote, null);


        SharedPreferences sharedPreferences2 = getContext().getSharedPreferences(getContext().getString(R.string.PREF_LOGIN), MODE_PRIVATE);
        fb_email = sharedPreferences2.getString(getString(R.string.email_signin), "");
        fb_name = sharedPreferences2.getString(getString(R.string.name_signin), "");
        fb_image = sharedPreferences2.getString(getString(R.string.image_signin), "");
        id_signin= sharedPreferences2.getString(getString(R.string.id_signin), "");
        coordinatorLayout = (LinearLayout) v.findViewById(R.id.coordinatorLayout);

        recycler_vote = (RecyclerView) v.findViewById(R.id.recycler_vote);
        LinearLayoutManager layoutManager = new LinearLayoutManager(this.getActivity());
        recycler_vote.setLayoutManager(layoutManager);
        recycler_vote.setNestedScrollingEnabled(false);
        recycler_vote.setItemAnimator(new DefaultItemAnimator());

        swipeRefreshLayout = (SwipeRefreshLayout) v.findViewById(R.id.swipe_refresh);
        swipeRefreshLayout.setOnRefreshListener(this);
        swipeRefreshLayout.setColorSchemeResources(R.color.colorGreen, R.color.black, R.color.colorRed);

        try {
            getData();


        } catch (Exception e) {
            e.printStackTrace();
        }

        return v;
    }


    public void getData() throws Exception {
        if (checkConnectivity()) {
            try {
                swipeRefreshLayout.setRefreshing(true);
                getAllMatchesVote();
            } catch (Exception e) {
                e.printStackTrace();

            }
        } else {
            swipeRefreshLayout.setRefreshing(false);

            // getAllPosts();
            showSnack();

        }
    }

    public boolean checkConnectivity() {
        return ConnectivityReceiver.isConnected();
    }

    public void showSnack() {

        Snackbar.make(coordinatorLayout, getString(R.string.no_internet_connected), Snackbar.LENGTH_INDEFINITE)
                .setAction(getString(R.string.settings), new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        startActivity(new Intent(Settings.ACTION_WIRELESS_SETTINGS));
                    }
                }).setActionTextColor(Color.RED)
                .show();
    }

    @Override
    public void onResume() {
        super.onResume();
        // Toast.makeText(getContext(),"u have resumed the app",Toast.LENGTH_SHORT).show();
        AppController.getInstance().setConnectivityReceiver(this);
    }


    @Override
    public void onRefresh() {
        try {
            //  Toast.makeText(getContext(),"u have refreshed the app",Toast.LENGTH_SHORT).show();

            //when u swipe the app..the getdata method is invoked !
            getData();
        } catch (Exception e) {
            e.printStackTrace();
        }

    }

    @Override
    public void onPause() {
        super.onPause();

        // Toast.makeText(getContext(),"u have paused the app",Toast.LENGTH_SHORT).show();
    }


    @Override
    public void onNetworkChange(boolean inConnected) {
        this.isConnected = inConnected;
        // Toast.makeText(getContext(),"the app network have been changed",Toast.LENGTH_SHORT).show();

    }

    public void getAllMatchesVote() throws Exception {
        final String TAG = "MATCH_VOTE";
        String url = Constants.MATCH_VOTE;
        StringRequest jsonObjectRequest = new StringRequest(Request.Method.POST, url, new Response.Listener<String>() {
            @Override
            public void onResponse(String response) {
                Log.i("response", response);
                parseJson(response);

            }
        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                try {

                    swipeRefreshLayout.setRefreshing(false);
                    Log.e("error", "" + error.getMessage());
                } catch (NullPointerException e) {
                    swipeRefreshLayout.setRefreshing(false);
                    e.printStackTrace();
                }


            }
        });

        AppController.getInstance().addToRequestQueue(jsonObjectRequest, TAG);

        swipeRefreshLayout.setRefreshing(false);

    }

    public void parseJson(String response) {

        try {

            JSONArray array = new JSONArray(response);
            JSONObject jsonObject = null;
            post_array.clear();
            Vote_valid_data p;
            for (int i = 0; i < array.length(); i++) {
                jsonObject = array.getJSONObject(i);

               /* String VOTE1 = jsonObject.getString("VOTE1");
                String VOTE2 = jsonObject.getString("VOTE2");
                String COUNT = jsonObject.getString("COUNT1");
                String TOTAL = jsonObject.getString("TOTAL"); */
                String id_livestream=jsonObject.getString("id_livestream");
                String name_match=jsonObject.getString("name_match");
                String name_team1= jsonObject.getString("name_team_1");
                String name_team2= jsonObject.getString("name_team_2");
                String image_team1= jsonObject.getString("image_team_1");
                String image_team2= jsonObject.getString("image_team_2");

                p = new Vote_valid_data();
                p.setId_livestream(id_livestream);
                p.setName_match(name_match);
                p.setName_team1(name_team1);
                p.setName_team2(name_team2);
                p.setImage_team1(image_team1);
                p.setImage_team2(image_team2);


                post_array.add(p);
                //realmHelper.save(p);
            }


        } catch (JSONException e) {

            swipeRefreshLayout.setRefreshing(false);
            e.printStackTrace();
            //Log.d("error", e.getMessage());
        }
        adapter = new PostAdapter6(getContext(), post_array);
        recycler_vote.setAdapter(adapter);
        swipeRefreshLayout.setRefreshing(false);

    }
    @Override
    public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
        inflater.inflate(R.menu.menu_main, menu);


        super.onCreateOptionsMenu(menu,inflater);
    }
}

XML layout for both two fragments :

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:ads="http://schemas.android.com/apk/res-auto"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/coordinatorLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    >

        <android.support.v4.widget.SwipeRefreshLayout
            android:id="@+id/swipe_refresh"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:layout_behavior="@string/appbar_scrolling_view_behavior">
            <android.support.v4.widget.NestedScrollView
                android:layout_width="match_parent"
                android:layout_height="wrap_content">

            <android.support.v7.widget.RecyclerView
                android:id="@+id/recycler_post"
                android:layout_width="match_parent"
                android:layout_height="wrap_content" />
            </android.support.v4.widget.NestedScrollView>

        </android.support.v4.widget.SwipeRefreshLayout>


</LinearLayout>

The activity that holds all fragments :

public class navigation extends AppCompatActivity
        implements NavigationView.OnNavigationItemSelectedListener {
    private TabLayout tabLayout;
    private TextView txt_developedby,txtName,txtWebsite,txt_points;
    private ImageView imgProfile;
    private View navHeader;
    private ViewPager viewPager;
    private String name,email,photo,id_signin;
    private int[] tabIcons = {
            R.drawable.ic_favorite_final,
            R.drawable.soccer_icon,
            R.drawable.ic_sort,
            R.drawable.video_icon,
            R.drawable.trophy_icon
    };


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        FacebookSdk.sdkInitialize(getApplicationContext());

        setContentView(R.layout.activity_navigation);

        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        try {
            setSupportActionBar(toolbar);
            getSupportActionBar().setDisplayShowTitleEnabled(false);


            if ((getIntent().getFlags() & Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT) != 0) {
                // Activity was brought to front and not created,
                // Thus finishing this will get us to the last viewed activity
                finish();
                return;
            }

            DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
            ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
                    this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
            drawer.setDrawerListener(toggle);
            toggle.syncState();

            NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
            navHeader=navigationView.getHeaderView(0);
            navigationView.setItemIconTintList(null);
            navigationView.setNavigationItemSelectedListener(this);
            txtName = (TextView)navHeader.findViewById(R.id.name);
            txtWebsite = (TextView)navHeader.findViewById(R.id.website);
           // txt_points = (TextView)navHeader.findViewById(R.id.txt_points);
            imgProfile = (ImageView)navHeader.findViewById(R.id.img_profile);
            viewPager = (ViewPager) findViewById(R.id.viewpager);
            setupViewPager(viewPager);

            tabLayout = (TabLayout) findViewById(R.id.tabs);
            tabLayout.setupWithViewPager(viewPager);
            setupTabIcons();
            SharedPreferences sharedPreferences = getApplicationContext().getSharedPreferences(getString(R.string.PREF_LOGIN), MODE_PRIVATE);
            name = sharedPreferences.getString(getString(R.string.name_signin), "");
            email = sharedPreferences.getString(getString(R.string.email_signin), "");
            photo = sharedPreferences.getString(getString(R.string.image_signin), "");
            id_signin = sharedPreferences.getString(getString(R.string.id_signin), "");


            if(name.equals("")) {
                navigationView.getMenu().clear();
                navigationView.inflateMenu(R.menu.activity_notregistered);            }
            else
            {
                navigationView.getMenu().clear();
                navigationView.inflateMenu(R.menu.activity_navigation_drawer);
            }

              if(name.equals("") && email.equals("") && photo.equals("")) {
                  //txtName.setText(getString(R.string.notregistered));
                  txtWebsite.setText(getString(R.string.User));
                  Glide.with(this).load(R.drawable.defaultimag)
                          .crossFade()
                          .thumbnail(0.5f)
                          .bitmapTransform(new CircleTransform(this))
                          .diskCacheStrategy(DiskCacheStrategy.ALL)
                          .into(imgProfile);


              }
              else {
                 // txtName.setText(name);
                  txtWebsite.setText(name);
                  // Loading profile image
                  Glide.with(this).load(photo)
                          .crossFade()
                          .thumbnail(0.5f)
                          .bitmapTransform(new CircleTransform(this))
                          .diskCacheStrategy(DiskCacheStrategy.ALL)
                          .into(imgProfile);
                  txt_developedby = (TextView) findViewById(R.id.footer_item_2);
                  txt_developedby.setMovementMethod(LinkMovementMethod.getInstance());
                  getAllPosts();
              }



        } catch (Exception e) {
            e.printStackTrace();
        }

    }


    private void setupTabIcons() {
        // tabLayout.getTabAt(0).setIcon(buildCounterDrawable(,R.drawable.ic_cart_count));
        tabLayout.getTabAt(0).setIcon(tabIcons[0]);
        tabLayout.getTabAt(1).setIcon(tabIcons[1]);
        tabLayout.getTabAt(2).setIcon(tabIcons[2]);
        tabLayout.getTabAt(3).setIcon(tabIcons[3]);
        tabLayout.getTabAt(4).setIcon(tabIcons[4]);



    }

    private void setupViewPager(ViewPager viewPager) {
        ViewPagerAdapter adapter = new ViewPagerAdapter(getSupportFragmentManager());
        adapter.addFrag(new OneFragment());
        adapter.addFrag(new SoccerFragment());
        adapter.addFrag(new StandingFragment());
        adapter.addFrag(new VideoFragment());
        adapter.addFrag(new WinnerFragment());


        viewPager.setAdapter(adapter);
    }

    class ViewPagerAdapter extends FragmentPagerAdapter {
        private final List<Fragment> mFragmentList = new ArrayList<>();
        private final List<String> mFragmentTitleList = new ArrayList<>();

        public ViewPagerAdapter(FragmentManager manager) {
            super(manager);
        }

        @Override
        public Fragment getItem(int position) {
            return mFragmentList.get(position);
        }

        @Override
        public int getCount() {
            return mFragmentList.size();
        }

        public void addFrag(Fragment fragment) {
            mFragmentList.add(fragment);
           // mFragmentTitleList.add(title);
        }


    }


    @Override
    public void onBackPressed() {
        try {

            DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
            if (drawer.isDrawerOpen(GravityCompat.START)) {
                drawer.closeDrawer(GravityCompat.START);
            } else {

                super.onBackPressed();
            }
        }catch (IllegalArgumentException e)
        {
            e.printStackTrace();
        }
    }


    @SuppressWarnings("StatementWithEmptyBody")
    @Override
    public boolean onNavigationItemSelected(MenuItem item) {
        // Handle navigation view item clicks here.
        int id = item.getItemId();

        if (id == R.id.share) {

            share();

        } else if (id == R.id.check) {
            check();

        } else if (id == R.id.feedback) {
            feedback();
        } else if (id == R.id.settings_notification) {
            Intent i = new Intent(getApplicationContext(), SettingsActivity.class);
            startActivity(i);
        }else if(id==R.id.signout_press)
        {
            SharedPreferences sharedPreferences = getApplicationContext().getSharedPreferences(getApplicationContext().getString(R.string.PREF_LOGIN_JUST_STATUS), MODE_PRIVATE);
            SharedPreferences.Editor editor = sharedPreferences.edit();
            editor.putString(getApplicationContext().getString(R.string.status_points), "false");
            editor.apply();
            LoginManager.getInstance().logOut();
            Intent i = new Intent(getApplicationContext(),MainActivity.class);
            startActivity(i);
            finish();

        }else if(id==R.id.signin_press)
        {
            Intent i = new Intent(getApplicationContext(),MainActivity.class);
            startActivity(i);
            finish();
        }
        else if(id==R.id.ic_team)
        {
            Intent i = new Intent(getApplicationContext(),TeamActivity.class);
            startActivity(i);
            finish();
        }

        DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
        drawer.closeDrawer(GravityCompat.START);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        int id = item.getItemId();
        if (id == R.id.action_settings) {
            rateMe();
        }

        return super.onOptionsItemSelected(item);
    }

    private void share() {
        try {
            int applicationNameId = this.getApplicationInfo().labelRes;
            final String appPackageName = this.getPackageName();
            Intent i = new Intent(Intent.ACTION_SEND);
            i.setType("text/plain");
            i.putExtra(Intent.EXTRA_SUBJECT, this.getString(applicationNameId));
            String link = "https://play.google.com/store/apps/details?id=" + appPackageName;
            i.putExtra(Intent.EXTRA_TEXT, getString(R.string.text) + " " + link);
            startActivity(Intent.createChooser(i, getString(R.string.shareapp)));
        } catch (Exception e) {

        }
    }

    private void rateMe() {
        Uri uri = Uri.parse("market://details?id=" + navigation.this.getPackageName());
        Intent goToMarket = new Intent(Intent.ACTION_VIEW, uri);
        // To count with Play market backstack, After pressing back button,
        // to taken back to our application, we need to add following flags to intent.
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            goToMarket.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY |
                    Intent.FLAG_ACTIVITY_NEW_DOCUMENT |
                    Intent.FLAG_ACTIVITY_MULTIPLE_TASK);
        }
        try {
            startActivity(goToMarket);
        } catch (ActivityNotFoundException e) {
            startActivity(new Intent(Intent.ACTION_VIEW,
                    Uri.parse("http://play.google.com/store/apps/details?id=" + navigation.this.getPackageName())));
        }
    }

    private void check() {
        Uri uri = Uri.parse("market://details?id=" + navigation.this.getPackageName());
        Intent goToMarket = new Intent(Intent.ACTION_VIEW, uri);
        // To count with Play market backstack, After pressing back button,
        // to taken back to our application, we need to add following flags to intent.
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            goToMarket.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY |
                    Intent.FLAG_ACTIVITY_NEW_DOCUMENT |
                    Intent.FLAG_ACTIVITY_MULTIPLE_TASK);
        }
        try {
            startActivity(goToMarket);
        } catch (ActivityNotFoundException e) {
            startActivity(new Intent(Intent.ACTION_VIEW,
                    Uri.parse("http://play.google.com/store/apps/details?id=" + navigation.this.getPackageName())));
        }

    }

    private void feedback() {
        try {
            Intent Email = new Intent(Intent.ACTION_SEND);
            Email.setType("text/email");
            Email.putExtra(Intent.EXTRA_EMAIL, new String[]{"alahedclub1@gmail.com"});
            Email.putExtra(Intent.EXTRA_SUBJECT, getString(R.string.feedbacksubject));
            Email.putExtra(Intent.EXTRA_TEXT, "");
            startActivity(Intent.createChooser(Email, getString(R.string.feedbacktitle)));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public void getAllPosts() throws Exception {
        final String TAG = "POINTS_URL";
        String url = Constants.POINTS_URL;
        StringRequest jsonObjectRequest = new StringRequest(Request.Method.POST, url, new Response.Listener<String>() {
            @Override
            public void onResponse(String response) {
              //  Log.i("response_points", response);
try {
    txtName.setText(response + " " + "points");
}catch (Exception e)
{
    e.printStackTrace();
}

            }
        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                try {


                    Log.e("error", "" + error.getMessage());
                } catch (NullPointerException e) {
                    e.printStackTrace();
                }


            }
        }) {
            @Override
            protected Map<String, String> getParams() throws AuthFailureError {

                Map<String, String> params = new HashMap<String, String>();
                params.put("email", id_signin);
                return params;
            }
        };


        AppController.getInstance().addToRequestQueue(jsonObjectRequest, TAG);

    }


}
Mahdi H
  • 339
  • 8
  • 24
  • How about viewPager.setOffscreenPageLimit(2)? then implement SwipeToRefreshLayout. So you don't have to reload 2 pages many times, just need to do it whenever user want to `pull to refresh` – phatnhse Aug 11 '17 at 16:24
  • viewPager.setOffscreenPageLimit(2) doesn't work. I have already implemented the pull to refresh in each fragment and it s working for the first time the fragments are being created but when switching between tabs and getting back to the fragments i am not able to refresh.. – Mahdi H Aug 11 '17 at 16:30
  • It's still working, I think. But the `SwipeToRefresh` view is set as `wrap_content` and there is no data inside. So, it can't work – phatnhse Aug 11 '17 at 16:36
  • @PhátPhát i have edited the question.. i added one of my two fragments code – Mahdi H Aug 11 '17 at 16:39
  • Can you help me to check that SwipeToRefresh layout is wrap_content or fill_parent? – phatnhse Aug 11 '17 at 16:40
  • Done.Would you please see the re-edited question. – Mahdi H Aug 11 '17 at 16:42
  • Yup. Can you help me one more favor? Outer activity, too – phatnhse Aug 11 '17 at 16:43
  • @PhátPhát done. – Mahdi H Aug 11 '17 at 16:47
  • @PhátPhát thanks it worked i found the solution i have added : viewPager.setOffscreenPageLimit(3) in the acitivity view pager. and let it as it was in fragment Soccer :viewPager.setOffscreenPageLimit(2) – Mahdi H Aug 11 '17 at 17:01
  • 1
    lol okay, Im writing the answer. Just like you said, by default, Viewpager will load 3 fragments into memory. Because you have just 5 tabs which implement SwipeToRefresh. So, they don't need to be created again. You can setOffscreenPageLimit(5) for outer activity. – phatnhse Aug 11 '17 at 17:04
  • Ref: https://stackoverflow.com/questions/18747975/difference-between-fragmentpageradapter-and-fragmentstatepageradapter – phatnhse Aug 11 '17 at 17:05
  • Please add your answer below, so others can follow – phatnhse Aug 11 '17 at 17:05
  • Yep thanks for explanation dear and i appreciate your help a lot. – Mahdi H Aug 11 '17 at 17:27

1 Answers1

0

Solution is :

Setting viewpager setOffscreenPageLimit(5) for outer activity.

And Setting viewpager setOffscreenPageLimit(2) for the two fragments.

Mahdi H
  • 339
  • 8
  • 24