【发布时间】:2012-07-30 20:54:37
【问题描述】:
现在我正在使用 Jake Wharton 的 ViewPagerIndicator 库。我在其中添加了几个Fragments,并且可以来回滑动。如果我将多个面板从Fragment 上滑开,那么它就会被移除(调用onDestroyView())。相反,如果我从Fragment 在一个面板内滑动,则它会被添加回来(调用onCreateView())。
当我的Fragment 再次被破坏/添加回来时,曾经存在于其中的Views 被破坏,我回到空白屏幕。我的Fragment 中有一个LinearLayout,我将TextViews 添加到其中。重新创建时在LinearLayout 上调用.size() 会显示正确的计数,但我无法弄清楚要调用什么才能再次显示它。我尝试在onResume() 中添加<LinearLayout>.requestLayout(),但没有成功。
如果我应该发布任何相关代码,请告诉我。但是,我认为这些都不是我的 Fragment 所特有的。
edit:所以最初我认为我必须处理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 本身。
标签: android android-layout android-fragments android-viewpager