Solved - Android ViewPager and TabLayout are not working fast

try to set

pager.setOffscreenPageLimit(no_of_fragments or pages);

Do all your task in asyctask on creation of fragments


I will suggest you to add the another method.

@Override
public void setMenuVisibility(boolean menuVisible) {
    super.setMenuVisibility(menuVisible);

    if (menuVisible) {
       Log.e("SetMenuVisibleFragmentA" , menuVisible + " ");
    }

}

public void setMenuVisibility (boolean menuVisible)

Set a hint for whether this fragment's menu should be visible. This is useful if you know that a fragment has been placed in your view hierarchy so that the user can not currently seen it, so any menu items it has should also not be shown.

Parameters

menuVisible :: The default is true, meaning the fragment's menu will be shown as usual. If false, the user will not see the menu.


Your

onActivityCreated(Bundle savedInstanceState1)"

in EquityFragment.java is weird. First of all, don't deactivate the StrictMode (because you ignore the thrown "NetworkOnMainThread" Exception which is most likely the reason for your code to be slow...)

Then look at the else Part:

 } else {
    new Thread(new Runnable() {
            @Override
            public void run() {
                // do some work here
                getActivity().runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        //   if (!isViewShown) {
                        new FetchAllData(getActivity(), 5).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
                        //    }
                    }
                });
            }
        }).start();
}

You start a new Thread, where you should do your network stuff. Instead of doing it, you return to the ui thread (if you do network stuff here the app will hang") in your new thread and do it on the ui thread. (I don't know what exactly FetchAllData does).

} else {
    new FetchAllData(getActivity(), 5).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}

should do the same Job.

In your FetchAllData class, you do all the JSON parsing in onPostExecute. Do the parsing in doInBackground and only set the adapter in onPostExecute.