【问题标题】:Maps in fragment crashes in sliding drawer when clicked twice on Maps item在地图项上单击两次时,片段中的地图在滑动抽屉中崩溃
【发布时间】:2015-02-02 11:56:55
【问题描述】:

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

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;
}

【问题讨论】:

    标签: maps fragment sliding drawer


    【解决方案1】:

    为了避免崩溃,我使用了我在 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;
    }
    

    【讨论】:

    • 我有很多来自 Slidingdrawer 的片段。当我按下 HomeFragment 并且它有一张地图时,当我再次点击它时它崩溃了。我该如何避免它??
    • try{ if (fragment != null) { fragment = getFragmentManager().findFragmentById(R.id.map); FragmentTransaction ft = getActivity().getFragmentManager().beginTransaction(); ft.remove(片段); ft.commit(); } } 捕捉(异常 e){ e.printStackTrace(); } Thread.interrupted(); super.onPause();
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多