大叔程序员的第九天 @动态添加Layout--用Radio进行切换
2013-03-13 15:33
387 查看
压力一级级下传,越来越大
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方法
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; } } }); }
相关文章推荐
- RelativeLayout动态添加控件(2)
- bootstrapValidator动态添加视图对添加后的视图进行校验
- LinearLayout 动态添加子Button,并自动换行
- android activity 动态添加 layout
- 几个常用控件的练习总结(radioButtonList,MultiView,Adratator,Literal,Panel控件中动态添加文本框)
- 切换tab,并且动态添加标签
- 关于LinnerLayout动态添加的控件 并且给子控件动态设置Id 、点击的问题
- 在xml中有一个LinearLayout,在fragment中动态加入多个Button,为其赋值并添加监听,然后加入到LinearLayout
- 在ListView中动态添加EditText并对其中的数据进行保存和由于复用引起的Editext中的内容显示异常的解决方案
- Delphi:RzPageControl(pagecontrol)实现多标签的动态添加,切换,关闭
- RadioGroup中动态添加RadioButton,RadioButton状态紊乱
- TableLayout动态添加和删除行
- 新特性:TabLayout动态添加条目
- GridView动态进行行添加和删除
- RzPageControl(pagecontrol)实现多标签的动态添加,切换,关闭
- TabLayout && ViewPager _动态添加Fragnent
- Android UI-实现底部切换标签之方式一 ──fragment(底部采用radioGroup+radiobutton)添加5个子fragment
- android中radioGroup动态添加radioButton
- Android中利用LinearLayout动态添加控件
- 抽屉布局加上RadioGroup+点击进行切换