*一般用於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;