سؤال

I'm currently facing a problem with my ViewPager. I've got a ViewPager with in the first tab a Listview, and in the second a FrameLayout to use the Google Maps Fragment (both called from a layout inflate via a different Fragment => ResultsListFragment and ResultsMapFragment).

When I change the fragment for my ViewPager fragment, it works for the first time, it load the data, etc... When I touch the back button, I return to my previous fragment (everything normal) but when I launch for a second time, the ResultsListFragment is create as it supposed, but not the ResultsMapFragment. The SupportMapFragment is created and found with the method findFragmentById() but not visible.

Does anyone has this problem ? Or know how I could fix it ?


Here the code into my ResultsMapFragment:

    mView = inflater.inflate(R.layout.fragment_pager_map_results, null, false);
    if (mView != null) {

        SupportMapFragment mMapFragment = ((SupportMapFragment) getSherlockActivity().getSupportFragmentManager().findFragmentById(R.id.map_fragment));
        if (mMapFragment == null) {
            FragmentManager fm = getFragmentManager();
            FragmentTransaction ft = fm.beginTransaction();
            mMapFragment = SupportMapFragment.newInstance();
            ft.replace(R.id.map_fragment, mMapFragment).commit();
        }

        if (mMapFragment != null) {
            mMap = mMapFragment.getPolarisMap();
            if (mMap != null) {
                Log.w(TAG, "onCreateView| " + "Found the google map by Polaris!!!");
                //// CODE TO ANIME VIEW, ETC...>>>

            } else
                Log.e(TAG, "onCreateView| " + "Ain't found the map by Polaris!!!");

        }

    }
هل كانت مفيدة؟

المحلول

Solved!

The problem was coming from the fact that I was using the getSupportFragmentManager instead of the getChildFragmentManager due to the nested design I'm using, I've just changed it in my ViewPager instantiation and it solved everything :)

Hope it would help anyone.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top