zoukankan      html  css  js  c++  java
  • 团队冲刺2.4

    1.今天继续学习fragment

    布局就不放了

    重要代码:

    MyFragment.java:

    
    public class MyFragment extends Fragment {
    
        private String content;
        public MyFragment(String content) {
            this.content = content;
        }
    
        @Override
        public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
            View view = inflater.inflate(R.layout.fg_content,container,false);
            TextView txt_content = (TextView) view.findViewById(R.id.txt_content);
            txt_content.setText(content);
            return view;
        }
    }
     public void onCheckedChanged(RadioGroup group, int checkedId) {
            FragmentTransaction fTransaction = fManager.beginTransaction();
            hideAllFragment(fTransaction);
            switch (checkedId){
                case R.id.rb_channel:
                    if(fg1 == null){
                        fg1 = new MyFragment("第一个Fragment");
                        fTransaction.add(R.id.ly_content,fg1);
                    }else{
                        fTransaction.show(fg1);
                    }
                    break;
                case R.id.rb_message:
                    if(fg2 == null){
                        fg2 = new MyFragment("第二个Fragment");
                        fTransaction.add(R.id.ly_content,fg2);
                    }else{
                        fTransaction.show(fg2);
                    }
                    break;
                case R.id.rb_better:
                    if(fg3 == null){
                        fg3 = new MyFragment("第三个Fragment");
                        fTransaction.add(R.id.ly_content,fg3);
                    }else{
                        fTransaction.show(fg3);
                    }
                    break;
                case R.id.rb_setting:
                    if(fg4 == null){
                        fg4 = new MyFragment("第四个Fragment");
                        fTransaction.add(R.id.ly_content,fg4);
                    }else{
                        fTransaction.show(fg4);
                    }
                    break;
            }
            fTransaction.commit();
        }
    
        //隐藏所有Fragment
        private void hideAllFragment(FragmentTransaction fragmentTransaction){
            if(fg1 != null)fragmentTransaction.hide(fg1);
            if(fg2 != null)fragmentTransaction.hide(fg2);
            if(fg3 != null)fragmentTransaction.hide(fg3);
            if(fg4 != null)fragmentTransaction.hide(fg4);
        }
     
  • 相关阅读:
    C/C++中extern关键字详解
    C/C++中static关键字详解
    MFC创建工程图解
    C++中L和_T()之区别
    C/C++中const关键字详解
    winfrom中,父窗体中只允许显示一个子窗体的代码怎么写?
    sql 批量插入
    visual studio .net ide : checking into source control now says checkIn Now (recursive)
    1.4 Turbo C V2.0的基本操作
    关于vs2003不能调试的解决方法
  • 原文地址:https://www.cnblogs.com/chenghaixiang/p/14914636.html
Copyright © 2011-2022 走看看