码迷,mamicode.com
首页 > 其他好文 > 详细

MainActivity

时间:2017-12-03 20:50:50      阅读:187      评论:0      收藏:0      [点我收藏+]

标签:init   nta   you   create   override   widget   example   undle   super   

package com.example.week;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.support.v7.app.AppCompatActivity;
import android.widget.FrameLayout;
import android.widget.RadioButton;
import android.widget.RadioGroup;

public class MainActivity extends FragmentActivity {

private RadioGroup gr;
private RadioButton shouye;
private RadioButton xigua;
private RadioButton wei;
private RadioButton wode;
private FrameLayout zhan;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
initView();
getSupportFragmentManager().beginTransaction().replace(R.id.zhan,new Fragment1()).commit();
gr.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
switch (checkedId){
case R.id.shouye:
getSupportFragmentManager().beginTransaction().
replace(R.id.zhan,new Fragment1()).commit();
break;
case R.id.xigua:
getSupportFragmentManager().beginTransaction().
replace(R.id.zhan, new Fragment2()).commit();
break;
case R.id.wei:
getSupportFragmentManager().beginTransaction().
replace(R.id.zhan,new Fragment3()).commit();
break;
case R.id.wode:
getSupportFragmentManager().beginTransaction().
replace(R.id.zhan,new Fragment4()).commit();
break;
}
}
});
}

private void initView() {
gr = (RadioGroup) findViewById(R.id.gr);
shouye = (RadioButton) findViewById(R.id.shouye);
xigua = (RadioButton) findViewById(R.id.xigua);
wei = (RadioButton) findViewById(R.id.wei);
wode = (RadioButton) findViewById(R.id.wode);
zhan = (FrameLayout) findViewById(R.id.zhan);
}
}

MainActivity

标签:init   nta   you   create   override   widget   example   undle   super   

原文地址:http://www.cnblogs.com/wangwensheng/p/7966982.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!