Fragment

2017-07-27  本文已影响0人  烟入墨

radioGroup.setOnCheckedChangeListener(new OnCheckedChangeListener() {

@Override

public void onCheckedChanged(RadioGroup group, int checkedId) {

// TODO Auto-generated method stub

switch (checkedId) {

case R.id.but01:

//创建FragmentManager管理者

FragmentManager fragmentManager=getSupportFragmentManager();

//通过FragmentManager开启一个事务

FragmentTransaction transaction=fragmentManager.beginTransaction();

//加载fragment  arg0  占位的控件  第二个参数是加载的Fragment

transaction.replace(R.id.fragment, new Fragment01());

//提交

transaction.commit();

break;

case R.id.but02:

FragmentManager fragmentManager2=getSupportFragmentManager();

FragmentTransaction transaction2=fragmentManager2.beginTransaction();

transaction2.replace(R.id.fragment, new Fragment02());

transaction2.commit();

break;

case R.id.but03:

FragmentManager fragmentManager3=getSupportFragmentManager();

FragmentTransaction transaction3=fragmentManager3.beginTransaction();

transaction3.replace(R.id.fragment, new Fragment03());

transaction3.commit();

break;

default:

break;

}

}

});

上一篇下一篇

猜你喜欢

热点阅读