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>