我正在使用ActionBarSherlock创建一个包含三个片段的滑动标签活动。每个片段都有一个自定义视图或在运行时添加的多个自定义视图,我希望能够保存片段的状态。我有进度条,我使用的只是米,当我旋转设备时,它们会回到0,当我转到最后的片段时,它会做同样的事情。我已经用不同的方式寻找了一段时间,包括setRetainInstance(true)和android:configChanges,但到目前为止还没有一个有效。请任何人帮助我。
以下是片段1的代码:
public class Fragment_1 extends SherlockFragment
{
private View view;
private PVLayout pvLayout; // Process value container view configuration class instance
private SlidingTabsActivity slidingTabsActivity;
private DeviceInfo deviceInfo;
private Page page;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
view = inflater.inflate(R.layout.fragment_pv, container, false);
return view;
}
@Override
public void onActivityCreated(Bundle savedInstanceState)
{
super.onActivityCreated(savedInstanceState);
setRetainInstance(true);
/* Creates the new views from the configuration class */
slidingTabsActivity = (SlidingTabsActivity) getSherlockActivity();
deviceInfo = slidingTabsActivity.getDeviceInfo();
page = slidingTabsActivity.getPage1();
pvLayout = new PVLayout(slidingTabsActivity);
pvLayout.setDeviceInfo(deviceInfo);
pvLayout.setPage(page);
pvLayout.createView();
}
}
片段2:
public class Fragment_2 extends SherlockFragment
{
private View view;
private ConfigLayout configLayout;
private SlidingTabsActivity slidingTabsActivity;
private DeviceInfo deviceInfo;
private Page page;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
view = inflater.inflate(R.layout.fragment_config, container, false);
return view;
}
@Override
public void onActivityCreated(Bundle savedInstanceState)
{
super.onActivityCreated(savedInstanceState);
setRetainInstance(true);
/* Creates the new view from the configuration class */
slidingTabsActivity = (SlidingTabsActivity) getSherlockActivity();
deviceInfo = slidingTabsActivity.getDeviceInfo();
page = slidingTabsActivity.getPage2();
configLayout = new ConfigLayout(slidingTabsActivity);
configLayout.setDeviceInfo(deviceInfo);
configLayout.setPage(page);
configLayout.createView();
}
}
片段3:
public class Fragment_3 extends SherlockFragment
{
private View view;
private DiagLayout diagLayout;
private SlidingTabsActivity slidingTabsActivity;
private DeviceInfo deviceInfo;
private Page page;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
view = inflater.inflate(R.layout.fragment_diag, container, false);
return view;
}
@Override
public void onActivityCreated(Bundle savedInstanceState)
{
super.onActivityCreated(savedInstanceState);
setRetainInstance(true);
/* Creates the new view from the configuration class */
slidingTabsActivity = (SlidingTabsActivity) getSherlockActivity();
deviceInfo = slidingTabsActivity.getDeviceInfo();
page = slidingTabsActivity.getPage3();
diagLayout = new DiagLayout(slidingTabsActivity);
diagLayout.setDeviceInfo(deviceInfo);
diagLayout.setPage(page);
diagLayout.createView();
}
}