我现在正在使用Jake Wharton的ViewPagerIndicator库。我已经添加了几个Fragments
到其中,并可以很好地向前和向后滑动。如果我从一个Fragment
中滑动超过一个面板,那么它就会被删除(onDestroyView()
被调用)。相反,如果我在一个面板内滑动一个Fragment
,那么它就会被添加回来(onCreateView()
被调用)。
当我的Fragment
被销毁/重新添加时,曾经存在于其中的Views
也被销毁了,我回到了一个空白屏幕。我在我的Fragment
中有一个LinearLayout
,我在其中添加TextViews
。当它重新创建时,在LinearLayout
上调用.size()
会显示正确的计数,但我无法弄清楚该调用什么以便再次显示它。我尝试在onResume()
中添加<LinearLayout>.requestLayout()
,但这没有起作用。
如果需要,让我知道是否应该发布任何相关代码。但我认为这些都不是特定于我的Fragment的内容。
编辑: 所以最初我想处理onSavedInstanceState()
,但我从来没有在其中保存整个布局。我另一个想法是迭代我的LinkedList
的TextViews
,然后将它们添加回到我的LinearLayout
中。这给了我一个错误,因为View
已经有父级,这是有道理的。
这是我如何添加我的TextView:
public void addQuickLook(QuickLookView v)
{
mViews2.add(v); //LinkedList of QuickLookViews
mMeterLayout.addView(v); //Adding to the LinearLayout
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
return inflater.inflate(R.layout.fragment_quicklook, container, false);
}
@Override
public void onActivityCreated(Bundle savedInstanceState)
{
super.onActivityCreated(savedInstanceState);
mMeterLayout = (LinearLayout) getActivity().findViewById(R.id.quickLookList);
}
ViewPager
的问题,它是支持库的一部分,而不是ViewPagerIndicator本身。 - Jake Wharton