由网友(恩赐.)分享简介:谷歌地图V2机器人负载的第一次,然后我切换到它的工作原理,当我回来的地图碎片它crashes.I都高度低于code等片段:我真的AP preciate任何帮助.Thanks提前。在fragmentMain $ C $下图:公共类FragmentMain扩展片段{的TextView TextView的;static fi...
谷歌地图V2机器人负载的第一次,然后我切换到它的工作原理,当我回来的地图碎片它crashes.I都高度低于code等片段:我真的AP preciate任何帮助.Thanks提前。
在fragmentMain $ C $下图:
公共类FragmentMain扩展片段{
的TextView TextView的;
static final的经纬度HAMBURG =新的经纬度(53.558,9.927);
static final的经纬度测试=新的经纬度(53.551,9.993);
私人GoogleMap的地图;
公共FragmentMain(){
}
@覆盖
公共查看onCreateView(LayoutInflater充气,容器的ViewGroup,
捆绑savedInstanceState){
查看查看= inflater.inflate(R.layout.fragment_main,NULL);
地图=((SupportMapFragment)getFragmentManager()findFragmentById(R.id.map)。)的GetMap()。
标记汉堡= map.addMarker(新MarkerOptions()。位置(汉堡)
.title伪(汉堡));
标记试验= map.addMarker(新MarkerOptions()
.position(试验)
.title伪(测试)
是.snippet(测试)
.icon(BitmapDescriptorFactory
.fromResource(R.drawable.ic_launcher)));
//瞬间将相机与汉堡的15变焦。
map.moveCamera(CameraUpdateFactory.newLatLngZoom(汉堡,15));
//放大,相机动画。
map.animateCamera(CameraUpdateFactory.zoomTo(10),2000,NULL);
返回查看;
}
}
$ C $下MainActivity:
FragmentManager FM = MainActivity.this.getSupportFragmentManager();
FragmentTransaction英尺= fm.beginTransaction();
片段片段= NULL;
如果(selectedItem.compareTo(第二)== 0){
片段=新FragmentMain();
}否则,如果(selectedItem.compareTo(第三)== 0){
片段=新FragmentButton();
}否则,如果(selectedItem.compareTo(第一)== 0){
片段=新FragmentCheckBox();
}
如果(片段!= NULL){
//这个新的替换当前片段
ft.replace(R.id.activity_main_content_fragment,片段);
ft.commit();
//设置标题相应
tvTitle.setText(将selectedItem);
}
错误:
致命异常:主要
android.view.InflateException:二进制XML文件中的行#83:错误充气类片段
在android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:713)
在android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
在android.view.LayoutInflater.inflate(LayoutInflater.java:492)
在android.view.LayoutInflater.inflate(LayoutInflater.java:397)
在android.view.LayoutInflater.inflate(LayoutInflater.java:353)
在com.mapsfragment.maps.FragmentMain.onCreateView(FragmentMain.java:32)
解决方案
只要把OnDestroyView()
这code 公共无效onDestroyView()
{
super.onDestroyView();
片段片段=(getFragmentManager()findFragmentById(R.id.map));
FragmentTransaction英尺= getActivity()getSupportFragmentManager()的BeginTransaction()。
ft.remove(片段);
ft.commit();
}
google maps v2 android loads the first time and then I am switching to other fragments which works when I come back to map fragment it crashes.I have attached the code below :I really appreciate any help .Thanks in Advance.
code for map in fragmentMain:
public class FragmentMain extends Fragment {
TextView textView;
static final LatLng HAMBURG = new LatLng(53.558, 9.927);
static final LatLng test = new LatLng(53.551, 9.993);
private GoogleMap map;
public FragmentMain() {
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_main, null);
map = ((SupportMapFragment) getFragmentManager().findFragmentById(R.id.map)).getMap();
Marker hamburg = map.addMarker(new MarkerOptions().position(HAMBURG)
.title("Hamburg"));
Marker test = map.addMarker(new MarkerOptions()
.position(test)
.title("test")
.snippet("test")
.icon(BitmapDescriptorFactory
.fromResource(R.drawable.ic_launcher)));
// Move the camera instantly to hamburg with a zoom of 15.
map.moveCamera(CameraUpdateFactory.newLatLngZoom(HAMBURG, 15));
// Zoom in, animating the camera.
map.animateCamera(CameraUpdateFactory.zoomTo(10), 2000, null);
return view;
}
}
code for MainActivity :
FragmentManager fm = MainActivity.this.getSupportFragmentManager();
FragmentTransaction ft = fm.beginTransaction();
Fragment fragment = null;
if(selectedItem.compareTo("second") == 0) {
fragment = new FragmentMain();
} else if(selectedItem.compareTo("third") == 0) {
fragment = new FragmentButton();
} else if(selectedItem.compareTo("first") == 0) {
fragment = new FragmentCheckBox();
}
if(fragment != null) {
// Replace current fragment by this new one
ft.replace(R.id.activity_main_content_fragment, fragment);
ft.commit();
// Set title accordingly
tvTitle.setText(selectedItem);
}
Error:
FATAL EXCEPTION: main
android.view.InflateException: Binary XML file line #83: Error inflating class fragment
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:713)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
at com.mapsfragment.maps.FragmentMain.onCreateView(FragmentMain.java:32)
解决方案
Just put this code on OnDestroyView()
public void onDestroyView()
{
super.onDestroyView();
Fragment fragment = (getFragmentManager().findFragmentById(R.id.map));
FragmentTransaction ft = getActivity().getSupportFragmentManager().beginTransaction();
ft.remove(fragment);
ft.commit();
}
相关推荐
最新文章