我有一个ABS和导航类型选项卡的应用程序。 在其中一个选项卡中,我有3个片段(不同排列的纵向/横向):其中一个有一个列表,一个有覆盖流,最后有一些搜索功能。当按下列表项目或覆盖流项目或搜索结果时,我打开哪些细节片段应该作为片段全屏加载。 另一个问题是,对于每个片段,我必须调用一个返回要显示的信息的web服务。但我无法并行调用它们,所以我首先加载列表,而不是coverflow,然后是搜索选项。否则,它会给出服务器错误,如:“连接仍然分配”。ABS +选项卡+片段问题
问题:配置上变化将不会按预期工作:我wan't细节,以根据新的配置,并在堆栈中的三个以某种方式没有装载所需的布局服务器错误:d
我已经试过: 1)无configChanges属性的活动,使该活动每次重新启动。这三种片段的作品,但是当我打开一个细节时,它给我提到了我提到的服务器错误。因为它试图在同一时间恢复来自backstack的所有3个片段以及细节片段。
看到logcat的输出:
12月6日至12日:31:38.511:E/EvenementsMainActitity(23833):的onCreate
12月6日至12日:31:38.551:E/NouveauLieuxFragment(23833):onCreateView
06-12 12:31:38.561:E/Top5Fragment(23833):onCreateView
06-12 12:31:38.571:E/RechercheFragment(23833):onCreateView
06-12 12:31:38.611:E/SalleDetailsFragment(23833):onCreateView
06-12 12:31:38.641:W/PhoneWindow(23833):以前重点查看报告ID 2131099775保存过程中,但无法找到期间恢复。
12月6日至12日:31:38.641:I/EvenementsMainActitity(23833):onResumeFragments
12月6日至12日:31:38.671:I/EvenementsMainActitity(23833):onTabSelected - 莱斯上装
06 -12 12:31:38.671:E/NouveauLieuxFragment(23833):onCreateView
06-12 12:31:38.681:W/SingleClientConnManager(23833):SingleClientConnManager的无效使用:连接仍然分配。
06-12 12:31:38.681:W/SingleClientConnManager(23833):确保在分配另一个连接之前释放连接。
12月6日至12日:31:38.721:E/Top5Fragment(23833):onCreateView 12月6日至12日:31:38.731:E/RechercheFragment(23833):onCreateView
12月6日至12日:31:38.831 :I /的CoverFlow(23833):中心的CoverFlow 427
12月6日至12日:31:38.851:E/SalleDetailsFragment(23833):GetSalleById错误服务器错误
12月6日至12日:31:38.851:W/System.err(23833):com.neurospeech.wsclient。SoapFaultException:服务器错误
- 其中EvenementsMainActitity是主要的活动; NouveauLieuxfragment,Top5Fragment和RechercheFragment是3个片段我谈论并SalleDetailsFragment是细节片段
- 我似乎无法理解为什么碎片
oncreateview
被称为两次:(
- 我似乎无法理解为什么碎片
2)为活动提供了configChanges属性,所以我写了onConfigurationChanged方法,但就像我做的那样,它只是恢复了我来自哪个标签,即使我在细节中。
3)现在我试图将细节变成一个活动,但这是非常困难的,因为我需要一堆变量,我必须通过捆绑包发送它们,而且我也不会有操作栏等。 ..
注意:我必须再次显示配置上的活动和片段更改导致方向不同的布局。
让我知道我有更多的信息或代码提供更好的理解。
编辑: 我有一个SherlockFragmentActivity包含选项卡,SherlockFragment for EACH选项卡和相同的细节。 比我有:
private class MyTabListener implements ActionBar.TabListener {
private final Activity mActivity;
public MyTabListener(Activity activity, String tag) {
mActivity = activity;
}
@Override
public void onTabSelected(Tab tab, final FragmentTransaction ft) {
....
tab_position = tab.getPosition();
switch (tab_position) {
...
case 1: // Les Tops
if (BuildMode.DEBUG) {
Log.i(TAG, "onTabSelected - Les Tops");
}
preInitializedFragment1 = (SherlockFragment) ((SherlockFragmentActivity) mActivity).getSupportFragmentManager()
.findFragmentByTag(fragments_mTags.get(2));
preInitializedFragment2 = (SherlockFragment) ((SherlockFragmentActivity) mActivity).getSupportFragmentManager()
.findFragmentByTag(fragments_mTags.get(10));
if (!isPhone)
preInitializedFragment3 = (SherlockFragment) ((SherlockFragmentActivity) mActivity).getSupportFragmentManager()
.findFragmentByTag(fragments_mTags.get(8));
if (preInitializedFragment1 == null && preInitializedFragment2 == null
&& ((!isPhone && preInitializedFragment3 == null) || isPhone)) {
frag1 = (SherlockFragment) SherlockFragment.instantiate(mActivity, NouveauLieuxFragment.class.getName());
ft.add(R.id.content1, frag1, fragments_mTags.get(2));
frag2 = (SherlockFragment) SherlockFragment.instantiate(mActivity, Top5Fragment.class.getName());
ft.add(R.id.content2, frag2, fragments_mTags.get(10));
if (!isPhone) {
frag3 = (SherlockFragment) SherlockFragment.instantiate(mActivity, RechercheFragment.class.getName());
ft.add(R.id.content3, frag3, fragments_mTags.get(8));
}
} else if (frag1 != null && frag2 != null && ((!isPhone && frag3 != null) || isPhone)) {
ft.attach(frag1);
ft.attach(frag2);
if (!isPhone)
ft.attach(frag3);
} else if (preInitializedFragment1 != null && preInitializedFragment2 != null
&& ((!isPhone && preInitializedFragment3 != null) || isPhone)) {
ft.attach(preInitializedFragment1);
ft.attach(preInitializedFragment2);
frag1 = preInitializedFragment1;
frag2 = preInitializedFragment2;
if (!isPhone) {
ft.attach(preInitializedFragment3);
frag3 = preInitializedFragment3;
}
}
loadLesTops();
break;
....
}
@Override
public void onTabUnselected(Tab tab, FragmentTransaction ft) {
....
// Detach the fragment, because another one is being attached
if (frag1 != null) {
ft.detach(frag1);
}
if (frag2 != null) {
ft.detach(frag2);
}
if (frag3 != null) {
ft.detach(frag3);
}
}
}
*配置上变化将不会按预期* - 这不是问题的一个明确的解释。关于如何处理这些片段的一些代码很好看。 – Luksprog