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);
        }
     
  • 相关阅读:
    前端优化分析 之 javascript放在底部
    HTML、SHTML、XHTML、DHTML、XML有什么不同
    web项目开发流程及规范
    sql developer连接mysql数据库
    hibernate自动创建表报错,提示不存在
    04关键字和标识符
    03注释与API文档
    WEB应用中的路径问题及乱码问题
    01java开发环境配置
    Eclipse Java EE IDE for Web Developers 4.5.1 安装hibername tools 插件
  • 原文地址:https://www.cnblogs.com/chenghaixiang/p/14914636.html
Copyright © 2011-2022 走看看