hyljava

          處理多個(gè)fragment之間replace刷新問題

           處理多個(gè)fragment之間replace刷新問題[轉(zhuǎn)]
           每次創(chuàng)建fragment對(duì)象都會(huì)重新走onCreateView方法,所以多個(gè)fragment互相替換會(huì)重新刷新界面,
           在application中創(chuàng)建一個(gè)View,保持onCreateVIew中創(chuàng)建的View
           每次走onCreateView的時(shí)候判斷application中是否保持了View,如果為null,重新inflater走initView和initData方法,不為nul得到父類,移除子View,不然有父id無(wú)法再加入布局中,
           以下是代碼:
           @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 何云隆 閱讀(557) 評(píng)論(0)  編輯  收藏 所屬分類: Android

          主站蜘蛛池模板: 湖北省| 吉首市| 石柱| 黄石市| 鄂尔多斯市| 红安县| 榆林市| 商洛市| 石楼县| 出国| 井冈山市| 九龙县| 仁布县| 元江| 女性| 台东市| 平武县| 思茅市| 巨野县| 富阳市| 白水县| 冷水江市| 锦州市| 博客| 景洪市| 禹州市| 阳泉市| 治多县| 漠河县| 崇州市| 东宁县| 遂宁市| 临城县| 炎陵县| 张家港市| 建宁县| 临高县| 洪江市| 吉木萨尔县| 封丘县| 和平县|