zoukankan      html  css  js  c++  java
  • 大叔程序员的第九天 @动态添加Layout用Radio进行切换

    压力一级级下传,越来越大

    private View in;
    private LinearLayout box;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    box = (LinearLayout)findViewById(R.id.box);
    in = View.inflate(this, R.layout.inside, null); //添加子页面
    box.addView(in);

    }

    动态添加一个子Layout至父Layout中去

    再增加用RadioGroup进行切换,主要是View.inflate()方法及checkedId的判断,还有是Layout对象的removeAllView方法和addView方法

    super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
            box = (LinearLayout)findViewById(R.id.box);
            radio = (RadioGroup)findViewById(R.id.radioGroup1);
            btn0 = (RadioButton)findViewById(R.id.radio0);
            btn1 = (RadioButton)findViewById(R.id.radio1);
            btn2 = (RadioButton)findViewById(R.id.radio2);
            box.addView(View.inflate(MainActivity.this, R.layout.taobao,null)); //添加子页面
            radio.setOnCheckedChangeListener(new OnCheckedChangeListener() {
                
                @Override
                public void onCheckedChanged(RadioGroup group, int checkedId) {
                    int i=0;
                    if(btn0.getId()==checkedId){
                        i=0;
                    }else if(btn1.getId()==checkedId){
                        i=1;
                    }else if(btn1.getId()==checkedId){
                            i=2;
                    }else{}
                    switch(i){
                    case 0:
                        box.removeAllViews();
                        box.addView(View.inflate(MainActivity.this, R.layout.taobao,null)); //添加子页面
                        break;
                    case 1:
                        Log.v("xxx","yyy");
                        box.removeAllViews();
                        box.addView(View.inflate(MainActivity.this, R.layout.product, null)); //添加子页面
                        break;
                    case 2:
                        box.removeAllViews();
                        box.addView(View.inflate(MainActivity.this, R.layout.service, null)); //添加子页面
                        break;
                    }
                    
                }
            });
            
            
        }
  • 相关阅读:
    手动实现 SpringMVC
    2014年9月9日 高级命令command的使用(上)
    2014年8月29日 透视图补充及视图开头
    2014年8月24日 菜单 工具条 右键菜单(上下文菜单)
    2014年8月14日 透视图
    2014年8月8日
    2014年8月1日
    关于EMF中从schema到ecore转变中的默认处理问题
    JAVA一些常用的时间操作
    echarts基本使用
  • 原文地址:https://www.cnblogs.com/linxiaojiang/p/2957737.html
Copyright © 2011-2022 走看看