hyljava

          處理多個fragment之間replace刷新問題

           處理多個fragment之間replace刷新問題[轉]
           每次創建fragment對象都會重新走onCreateView方法,所以多個fragment互相替換會重新刷新界面,
           在application中創建一個View,保持onCreateVIew中創建的View
           每次走onCreateView的時候判斷application中是否保持了View,如果為null,重新inflater走initView和initData方法,不為nul得到父類,移除子View,不然有父id無法再加入布局中,
           以下是代碼:
           @Override
           public View onCreateView(LayoutInflater inflater, ViewGroup container,
             Bundle savedInstanceState) {
            
            GalaxyApplication galaxyApplication = (GalaxyApplication) getActivity().getApplication();
            View recommendView = galaxyApplication.getRecommendView();
            if(recommendView != null){
             
             ViewGroup group = (ViewGroup) recommendView.getParent();
             group.removeAllViews();
             
             return recommendView;
            }
            
            View fmRootView = inflater.inflate(R.layout.fragment_recommend, container,false);
            
            
           
            
            initView(fmRootView);
            initData();
            galaxyApplication.setRecommendView(fmRootView);
            Logger.d("fragment: ", "onCreateView");
            return fmRootView;
           } 

           如有好的方法,處理onCreateView刷新問題  歡迎留言。 

          posted on 2014-02-22 22:55 何云隆 閱讀(555) 評論(0)  編輯  收藏 所屬分類: Android

          主站蜘蛛池模板: 武川县| 博罗县| 莎车县| 穆棱市| 临城县| 南召县| 百色市| 珠海市| 南岸区| 漳浦县| 南城县| 毕节市| 安远县| 遂昌县| 五大连池市| 富蕴县| 什邡市| 北宁市| 津市市| 石家庄市| 临桂县| 靖江市| 大悟县| 延吉市| 广水市| 久治县| 旅游| 上犹县| 平果县| 广元市| 麻江县| 泸州市| 阳江市| 鲁甸县| 贞丰县| 马鞍山市| 井冈山市| 嵊泗县| 白城市| 三原县| 无为县|