private int tabIndex;
class MyTabListener implements TabListener {// 3.changed
<span style="white-space:pre"> </span>// 接收每个Tab对应的Fragment,操作
<span style="white-space:pre"> </span>private Fragment fragment;
<span style="white-space:pre"> </span>private Fragment [] fragments ={fSet,fPlate,fCurve,fResult,fFile};
略
public void onTabSelected(Tab tab, FragmentTransaction ft) {
//切换后可保存界面状态
FragmentTransaction transaction = getFragmentManager().beginTransaction();
transaction.add(R.id.main_titles, fragment);
transaction.addToBackStack(null);
if (tabIndex > -1)
transaction.hide(fragments[tabIndex]);
transaction.show(fragment);
transaction.commit();
tabIndex = tab.getPosition();
}
}
采用show,hide的方法实现保存fragment的状态