在地图项目上单击两次时,片段中的地图会在滑动抽屉中崩溃

时间:2015-02-02 11:56:56

标签: maps fragment sliding drawer

在地图项目

上点击两次时,滑动抽屉中的地图碎片崩溃
public View onCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState) {

    View rootView = inflater.inflate(R.layout.map_fine_tech, container, false);
    fragment =  getFragmentManager().findFragmentById(R.id.map);
    return rootView;
}

1 个答案:

答案 0 :(得分:0)

为了避免崩溃,我使用全局变量,我在MyApplication类中声明了从Application

扩展的类
MyApplication app = (MyApplication) getApplicationContext();
boolean mapstate = app.isMapstate();
String bvalue = String.valueOf(mapstate);
Log.e("tag1", bvalue);
Fragment fragment = null;

switch (position) {
case 0:
    fragment = new UserProfileScreen();
    app.setMapstate(false);
    String c = String.valueOf(mapstate);
    Log.e("case0", c);
    break;
case 1:
    if(mapstate==false)
    {
        fragment = new MapFineTech();
        app.setMapstate(true);
        String bvalue2 = String.valueOf(mapstate);
        Log.e("tag2", bvalue2);
    }
    else
    {

    }
    break;
}