package com.bwei.zonghe_8; import android.support.v4.app.Fragment; import android.support.v4.app.FragmentManager; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.View; import android.widget.RadioGroup; import com.bwei.base.BaseActivity; import com.bwei.fragment.Fragment1; import com.bwei.fragment.Fragment2; import com.bwei.fragment.Fragment3; import com.bwei.fragment.Fragment4; import java.util.ArrayList; public class MainActivity extends BaseActivity { private RadioGroup radio; private ArrayList<Fragment> list; private FragmentManager manager; @Override protected void initData() { list = new ArrayList<>(); list.add(new Fragment1()); list.add(new Fragment2()); list.add(new Fragment3()); list.add(new Fragment4()); manager = getSupportFragmentManager(); changeCheck(list.get(0)); radio.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() { @Override public void onCheckedChanged(RadioGroup radioGroup, int i) { switch (i){ case R.id.rb1: changeCheck(list.get(0)); break; case R.id.rb2: changeCheck(list.get(1)); break; case R.id.rb3: changeCheck(list.get(2)); break; case R.id.rb4: changeCheck(list.get(3)); break; } } }); } private void changeCheck(Fragment fragment) { manager.beginTransaction().replace(R.id.f1,fragment).commit(); } @Override protected void init() { radio = findViewById(R.id.radio); } @Override protected int initlayout() { return R.layout.activity_main; } }
BaseMan
最新推荐文章于 2024-05-17 18:50:14 发布