fragment和radiobutton

public class Main2Activity extends AppCompatActivity implements View.OnClickListener {
    private RadioButton zuixin;
    private RadioButton zhuanlan;
    private RadioButton remen;
    private RadioButton zhuti;
    private RadioGroup rg;
    private FrameLayout fl;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main2);
        initView();
        Fragment1 F1=new Fragment1();
        getSupportFragmentManager().beginTransaction().replace(R.id.fragment,F1).commit();
        zuixin.setOnClickListener(this);
        zhuanlan.setOnClickListener(this);
        remen.setOnClickListener(this);
        zhuti.setOnClickListener(this);

    }


    private void initView() {
        zuixin = (RadioButton) findViewById(R.id.zuixin);
        zhuanlan = (RadioButton) findViewById(R.id.zhuanlan);
        remen = (RadioButton) findViewById(R.id.remen);
        zhuti = (RadioButton) findViewById(R.id.zhuti);
        rg = (RadioGroup) findViewById(R.id.rg);
        fl = (FrameLayout) findViewById(R.id.fragment);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.zuixin:
                Fragment1 F1 = new Fragment1();
                getSupportFragmentManager().beginTransaction().replace(R.id.fragment, F1).commit();
                break;
            case R.id.zhuanlan:
                Fragment2 F2 = new Fragment2();
                getSupportFragmentManager().beginTransaction().replace(R.id.fragment, F2).commit();
                break;
            case R.id.remen:
                Fragment3 F3 = new Fragment3();
                getSupportFragmentManager().beginTransaction().replace(R.id.fragment, F3).commit();
                break;
            case R.id.zhuti:
                Fragment4 F4 = new Fragment4();
                getSupportFragmentManager().beginTransaction().replace(R.id.fragment, F4).commit();
                break;

        }
    }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值