Kas*_*chi 0 android android-fragments
我正在开发一个使用片段标签的应用程序,我的一个片段使用Google Maps V2" SupportMapFragment"
public class A extends Fragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState)
{
View view = null;
view = inflater.inflate(R.layout.all_coffee_shops_view, container, false);
map = ((SupportMapFragment) getActivity().getSupportFragmentManager()
.findFragmentById(R.id.map)).getMap();
}
}
Run Code Online (Sandbox Code Playgroud)
我的xml:
<RelativeLayout
android:id="@+id/map_container"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<fragment
android:id="@+id/map"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
class="com.google.android.gms.maps.SupportMapFragment"
/>
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
我从这个A片段(A-> B)调用B Fragment,当我从B->返回时,一个片段onCreateView抛出一个异常,"android.view.InflateException:二进制XML文件行#132:错误膨胀类片段"
当一旦fragment创建了map 并且再次返回到这个片段时,onCreateView()就会调用片段,这就是你强行关闭的原因
在包含地图的片段中尝试一次
@Override
public void onDestroyView() {
super.onDestroyView();
Fragment f = getFragmentManager().findFragmentById(R.id.map);
if (f != null)
getFragmentManager().beginTransaction().remove(f).commit();
}
Run Code Online (Sandbox Code Playgroud)
请评论我的结果
| 归档时间: |
|
| 查看次数: |
2769 次 |
| 最近记录: |