zoukankan      html  css  js  c++  java
  • Fragment重叠问题

    1:实例代码

        
        private void showFragment(int index){
            //开启事物
            FragmentTransaction transaction = manager.beginTransaction();
            hideFragment(transaction);
            switch (index) {
            case 0:
                if(fragment1 != null){//如过已经实例化,那么可直接显示出来
                    transaction.show(fragment1);
                }else{//如果没有实例化,先实例化,在添加
                    fragment1 = new TabFragment1();
                    transaction.add(R.id.content, fragment1);
                }
                break;
            case 1:
                if(fragment2 != null){
                    transaction.show(fragment2);
                }else{
                    fragment2 = new TabFragment2();
                    transaction.add(R.id.content, fragment2);
                }
                
                break;
            case 2:
                if(fragment3 != null){
                    transaction.show(fragment3);
                }else{
                    fragment3 = new TabFragment3();
                    transaction.add(R.id.content, fragment3);
                }
                break;
    
            default:
                break;
            }
            transaction.commit();//切记要提交事物
        }
        
        
        
        /**
         * 隐藏所有的Fragment
         * @param ft
         */
        private void hideFragment(FragmentTransaction ft){
            if(fragment1 != null){
                ft.hide(fragment1);
            }
            if(fragment2 != null){
                ft.hide(fragment2);
            }
            if(fragment3 != null){
                ft.hide(fragment3);
            }
            
        }
  • 相关阅读:
    CF 848C
    BZOJ 4025 二分图
    支配树学习笔记
    CF1120D Power Tree
    Codeforces 360A(找性质)
    Codeforces 142D(博弈)
    Codeforces 142B(二分染色、搜索)
    GYM 101981E(开关反转性质)
    Codeforces 1150E(树、线段树)
    Codeforces 1150D(字符串dp)
  • 原文地址:https://www.cnblogs.com/wei1228565493/p/4774460.html
Copyright © 2011-2022 走看看