我的 ViewPager
目前遇到问题。我有一个 ViewPager,在第一个选项卡中有一个 Listview
,在第二个选项卡中有一个 FrameLayout 以使用 Google Maps Fragment
(均通过不同的 Fragment
=> ResultsListFragment
和 从布局调用ResultsMapFragment
)。
当我为我的 ViewPager
fragment 更改 fragment 时,它第一次工作,它加载数据等......当我触摸后退按钮时,我返回到我之前的 fragment (一切正常)但是当我第二次启动时,ResultsListFragment
是按预期创建的,但不是 ResultsMapFragment
。 SupportMapFragment
是使用 findFragmentById() 方法创建和找到的,但不可见。
有人遇到过这个问题吗?或者知道我该如何解决它?
这里是我的 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!!!");
}
}
最佳答案
解决了!
问题是因为我使用的是 getSupportFragmentManager
而不是 getChildFragmentManager
由于我使用的是嵌套设计,我刚刚在我的 ViewPager 实例化中更改了它,它解决了所有问题:)
希望对大家有帮助。
关于android - 返回 ViewPager,我的 GoogleMap fragment 不可见,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22808398/