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);
        }
     
  • 相关阅读:
    DigCSDN介绍首页
    相似qq的IM聊天应用源代码
    iOS单元測试:Specta + Expecta + OCMock + OHHTTPStubs + KIF
    struts2訪问servlet的API
    Reorg
    开源 免费 java CMS
    hdu1874 畅通project续(求最短路径)
    在64位系统下,指向int型的指针占的内存空间多大?
    linux中mv命令使用详解
    C语言中%d,%p,%u,%lu等都有什么用处
  • 原文地址:https://www.cnblogs.com/chenghaixiang/p/14914636.html
Copyright © 2011-2022 走看看