public class MainActivity extends AppCompatActivity { private FrameLayout frameLayout; private RadioGroup group; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); frameLayout = (FrameLayout) findViewById(R.id.fream); group = (RadioGroup) findViewById(R.id.group); getSupportFragmentManager().beginTransaction().replace(R.id.fream, new Fragment_Sy()).commit(); group.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() { @Override public void onCheckedChanged(RadioGroup group, @IdRes int checkedId) { switch (checkedId){ case R.id.rb1: getSupportFragmentManager().beginTransaction().replace(R.id.fream, new Fragment_Sy()).commit(); break; case R.id.rb2: getSupportFragmentManager().beginTransaction().replace(R.id.fream, new Fragment_Fx()).commit(); break; case R.id.rb3: getSupportFragmentManager().beginTransaction().replace(R.id.fream, new Fragment_Ss()).commit(); break; case R.id.rb4: getSupportFragmentManager().beginTransaction().replace(R.id.fream, new Fragment_My()).commit(); break; } } }); } }
Fragment和ViewPager的替换关联
最新推荐文章于 2020-02-19 22:23:07 发布