Fragment的使用

Fragment切换与RadioGroup示例
private RadioGroup rg;
private RadioButton bt1,bt2,bt3,bt4;
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.mainfragment01, container, false);
     bt1 = view.findViewById(R.id.bt1);
     bt2 = view.findViewById(R.id.bt2);
     bt3 = view.findViewById(R.id.bt3);
     bt4 = view.findViewById(R.id.bt4);
    rg = view.findViewById(R.id.rg);
    getActivity().getSupportFragmentManager().beginTransaction().replace(R.id.frag,new Fragment01()).commit();
    bt1.setTextColor(Color.RED);
    bt2.setTextColor(Color.BLACK);
    bt3.setTextColor(Color.BLACK);
    bt4.setTextColor(Color.BLACK);
    rg.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(RadioGroup radioGroup, @IdRes int i) {
            switch (i){
                case R.id.bt1:
                    getActivity().getSupportFragmentManager().beginTransaction().replace(R.id.frag,new Fragment01()).commit();
                    bt1.setTextColor(Color.RED);
                    bt2.setTextColor(Color.BLACK);
                    bt3.setTextColor(Color.BLACK);
                    bt4.setTextColor(Color.BLACK);
                    break;
                case R.id.bt2:
                    getActivity().getSupportFragmentManager().beginTransaction().replace(R.id.frag,new Fragment02()).commit();
                    bt1.setTextColor(Color.BLACK);
                    bt2.setTextColor(Color.RED);
                    bt3.setTextColor(Color.BLACK);
                    bt4.setTextColor(Color.BLACK);
                    break;
                case R.id.bt3:
                    getActivity().getSupportFragmentManager().beginTransaction().replace(R.id.frag,new Fragment03()).commit();
                    bt1.setTextColor(Color.BLACK);
                    bt2.setTextColor(Color.BLACK);
                    bt3.setTextColor(Color.RED);
                    bt4.setTextColor(Color.BLACK);
                    break;
                case R.id.bt4:
                    getActivity().getSupportFragmentManager().beginTransaction().replace(R.id.frag,new Fragment04()).commit();
                    bt1.setTextColor(Color.BLACK);
                    bt2.setTextColor(Color.BLACK);
                    bt3.setTextColor(Color.BLACK);
                    bt4.setTextColor(Color.RED);
                    break;
            }
        }
    });


    return view;

}

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <FrameLayout
        android:id="@+id/frag"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="9" />



    <RadioGroup
        android:id="@+id/rg"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal">

        <RadioButton
            android:id="@+id/bt1"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:button="@null"
            android:gravity="center"
            android:text="首页"
            android:textSize="20sp" />

        <RadioButton
            android:id="@+id/bt2"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:button="@null"
            android:gravity="center"
            android:text="自选"
            android:textSize="20sp" />

        <RadioButton
            android:id="@+id/bt3"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:button="@null"
            android:gravity="center"
            android:text="行情"
            android:textSize="20sp" />

        <RadioButton
            android:id="@+id/bt4"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:button="@null"
            android:gravity="center"
            android:text="咨询"
            android:textSize="20sp" />

    </RadioGroup>

</LinearLayout>

## 01、数据介绍 数据整理全国30个省份制造业细分行业产值,能够反映一定时期内细分行业工业生产总规模和总水平的指标,是计算工业生产发展速度和主要比例关系、计算工业产品销售率等其他经济指标的基础。先进制造业数据可用于两业融合测算。 数据名称:全国30省-制造业细分行业产值/先进制造业细分行业产值数据 数据年份:2001-2022年 ## 02、数据指标 农副食品加工业;食品制造业;饮料制造业;烟草制造业;纺织业;纺织服装鞋帽制造业;皮革、毛皮、羽毛(绒)极其制品业;木材加工及木、竹、藤、棕、草制品业;家具制造业;造纸及纸制品业;印刷业和记录媒介的复制;文教体育用品制造业;石油加工、炼焦及核燃料加工业化;学原料及化学制品制造业;医药制造业;化学纤维制造业;橡胶和塑料制品制品业;非金属矿物制品业;黑色金属冶炼及压延加工业;有色金属冶炼及压延加工业;金属制品业;通用设备制造业;专用设备制造业;汽车制造业;其他运输设备制造业;电气机械及器材制造业;通信设备计算机及其他电子设备制造业;仪器仪表及文化、办公用机械制造业;其他制造业;废弃资源和废旧材料回收加工业;制造业总产值 印刷业和记录媒介的复制;石油加工、炼焦及核燃料加工业;化学原料及化学制品制造业;医药制造业;橡胶和塑料制品制品业;非金属矿物制品业;黑色金属冶炼及压延加工业;有色金属冶炼及压延加工业;金属制品业;通用设备制造业;专用设备制造业;汽车制造业;其他运输设备制造业;电气机械及器材制造业;通信设备计算机及其他电子设备制造业;仪器仪表及文化、办公用机械制造业;废弃资源和废旧材料回收加工业
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值