Activity操作
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.RelativeLayout;
import com.example.yf.zk03.fragment.FragmentOne;
import com.example.yf.zk03.fragment.FragmentThree;
import com.example.yf.zk03.fragment.FragmentTwo;
import com.example.yf.zk03.fragment.Fragmentfour;
public class ShowActivity extends AppCompatActivity {
private RelativeLayout relative;
private RadioGroup radio_group;
private RadioButton rb1;
private RadioButton rb2;
private RadioButton rb3;
private RadioButton rb4;
private FragmentOne fragmentOne;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_show);
relative = findViewById(R.id.relative);
radio_group = findViewById(R.id.radio_group);
rb1 = findViewById(R.id.rb1);
rb2 = findViewById(R.id.rb2);
rb3 = findViewById(R.id.rb3);
rb4 = findViewById(R.id.rb4);
final FragmentManager manager = getSupportFragmentManager();
FragmentTransaction transaction = manager.beginTransaction();
fragmentOne = new FragmentOne();
transaction.add(R.id.relative,fragmentOne);
transaction.commit();
radio_group.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
private Fragmentfour fragmentfour;
private FragmentThree fragmentThree;