BaseMan

package com.bwei.zonghe_8;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.RadioGroup;

import com.bwei.base.BaseActivity;
import com.bwei.fragment.Fragment1;
import com.bwei.fragment.Fragment2;
import com.bwei.fragment.Fragment3;
import com.bwei.fragment.Fragment4;

import java.util.ArrayList;

public class MainActivity extends BaseActivity {

    private RadioGroup radio;
    private ArrayList<Fragment> list;
    private FragmentManager manager;

    @Override
    protected void initData() {
        list = new ArrayList<>();
        list.add(new Fragment1());
        list.add(new Fragment2());
        list.add(new Fragment3());
        list.add(new Fragment4());
        manager = getSupportFragmentManager();
        changeCheck(list.get(0));
        radio.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup radioGroup, int i) {
                switch (i){
                    case R.id.rb1:
                        changeCheck(list.get(0));
                        break;
                    case R.id.rb2:
                        changeCheck(list.get(1));
                        break;
                    case R.id.rb3:
                        changeCheck(list.get(2));
                        break;
                    case R.id.rb4:
                        changeCheck(list.get(3));
                        break;
                }
            }
        });
    }

    private void changeCheck(Fragment fragment) {
        manager.beginTransaction().replace(R.id.f1,fragment).commit();
    }

    @Override
    protected void init() {
        radio = findViewById(R.id.radio);
    }

    @Override
    protected int initlayout() {
        return R.layout.activity_main;
    }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值