Fragment显示隐藏

package com.example.day14;

import android.os.Bundle;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.support.v7.app.AppCompatActivity;
import android.widget.FrameLayout;
import android.widget.RadioButton;
import android.widget.RadioGroup;

import com.example.day14.fragment.Fragment_1;
import com.example.day14.fragment.Fragment_2;
import com.example.day14.fragment.Fragment_3;
import com.example.day14.fragment.Fragment_4;
import com.example.day14.fragment.Fragment_5;

import butterknife.BindView;
import butterknife.ButterKnife;

public class Main4Activity extends AppCompatActivity {

    @BindView(R.id.FrameLayout1)
    FrameLayout FrameLayout1;
    @BindView(R.id.RadioButton1)
    RadioButton RadioButton1;
    @BindView(R.id.RadioButton2)
    RadioButton RadioButton2;
    @BindView(R.id.RadioButton3)
    RadioButton RadioButton3;
    @BindView(R.id.RadioButton4)
    RadioButton RadioButton4;
    @BindView(R.id.RadioButton5)
    RadioButton RadioButton5;
    @BindView(R.id.RadioGroup1)
    RadioGroup RadioGroup1;
    private FragmentManager supportFragmentManager;
    private Fragment_1 fragment_1;
    private Fragment_2 fragment_2;
    private Fragment_3 fragment_3;
    private Fragment_4 fragment_4;
    private Fragment_5 fragment_5;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main4);
        ButterKnife.bind(this);

        fragment_1 = new Fragment_1();
        fragment_2 = new Fragment_2();
        fragment_3 = new Fragment_3();
        fragment_4 = new Fragment_4();
        fragment_5 = new Fragment_5();
        supportFragmentManager = getSupportFragmentManager();
        FragmentTransaction fragmentTransaction = supportFragmentManager.beginTransaction();
        fragmentTransaction.add(R.id.FrameLayout1,fragment_1)
                .add(R.id.FrameLayout1,fragment_2)
                .add(R.id.FrameLayout1,fragment_3)
                .add(R.id.FrameLayout1,fragment_4)
                .add(R.id.FrameLayout1,fragment_5)
                .show(fragment_1).hide(fragment_2).hide(fragment_3).hide(fragment_4).hide(fragment_5).commit();


        RadioGroup1.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup radioGroup, int i) {
                FragmentTransaction fragmentTransaction1 = supportFragmentManager.beginTransaction();
                switch (i){
                    case R.id.RadioButton1:
                        fragmentTransaction1.show(fragment_1)
                                .hide(fragment_2).hide(fragment_3).hide(fragment_4).hide(fragment_4).hide(fragment_5);
                        break;
                    case R.id.RadioButton2:
                        fragmentTransaction1.show(fragment_2)
                                .hide(fragment_1).hide(fragment_3).hide(fragment_4).hide(fragment_4).hide(fragment_5);
                        break;
                    case R.id.RadioButton3:
                        fragmentTransaction1.show(fragment_3)
                                .hide(fragment_2).hide(fragment_1).hide(fragment_4).hide(fragment_4).hide(fragment_5);
                        break;
                    case R.id.RadioButton4:
                        fragmentTransaction1.show(fragment_4)
                                .hide(fragment_2).hide(fragment_3).hide(fragment_1).hide(fragment_4).hide(fragment_5);
                        break;
                    case R.id.RadioButton5:
                        fragmentTransaction1.show(fragment_5)
                                .hide(fragment_2).hide(fragment_3).hide(fragment_4).hide(fragment_4).hide(fragment_1);
                        break;
                }
                fragmentTransaction1.commit();
            }
        });
    }
}

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

   <FrameLayout
       android:id="@+id/FrameLayout1"
       android:layout_width="match_parent"
       android:layout_height="0dp"
       android:layout_weight="9"
       >
    </FrameLayout>
    <RadioGroup
        android:id="@+id/RadioGroup1"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:orientation="horizontal"
        >
        <RadioButton
            android:id="@+id/RadioButton1"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:button="@null"
            android:background="#3c3"
            android:gravity="center"
            android:text="全部订单"
            />
        <RadioButton
            android:id="@+id/RadioButton2"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:button="@null"
            android:background="#3c3c"
            android:gravity="center"
            android:text="待付款"
            />
        <RadioButton
            android:id="@+id/RadioButton3"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:button="@null"
            android:background="#3c3c"
            android:gravity="center"
            android:text="待收货"
            />
        <RadioButton
            android:id="@+id/RadioButton4"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:button="@null"
            android:background="#3c3c3c"
            android:gravity="center"
            android:text="待评价"
        />
        <RadioButton
            android:id="@+id/RadioButton5"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:button="@null"
            android:background="#34C"
            android:gravity="center"
            android:text="已完成"
            />

    </RadioGroup>

</LinearLayout>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".Main4Activity"
    android:orientation="vertical"
    >
  <android.support.v7.widget.RecyclerView
      android:id="@+id/RecyclerView1"
      android:layout_width="match_parent"
      android:layout_height="match_parent">

  </android.support.v7.widget.RecyclerView>

</LinearLayout>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

王富贵王富贵王富贵

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值