*一般用于tab主页中又含有tab效果的界面中,亦可单独代替tab使用。
上效果图:
初始化的时候为界面添加一个fragment。
private void init_date(){
transaction = getFragmentManager()
.beginTransaction();
if (null == mSpeeddialFragmentOne) {
mSpeeddialFragmentOne = new SpeeddialFragmentOne();
}
transaction.add(R.id.fragment_container,
mSpeeddialFragmentOne);
// Commit the transaction
transaction.commit();
}
以后每次点击radiobutton的时候,用新fragment替换掉已经存在的那个fragment。
switch (checkedId) {
case R.id.radio0:
if (null == mSpeeddialFragmentOne) {
mSpeeddialFragmentOne = new SpeeddialFragmentOne();
}
transaction = getFragmentManager()
.beginTransaction();
transaction.replace(R.id.fragment_container,
mSpeeddialFragmentOne);
// Commit the transaction
transaction.commit();
break;