现在我正在使用Jake Wharton的ViewPagerIndicator库。我已经添加了几个Fragments
,并且可以来回滑动。如果我从Fragment
以上滑动多个面板,则会将其移除(调用onDestroyView()
)。相反,如果我从Fragment
的一个面板中滑动,则会将其添加回(onCreateView()
调用)。ViewPager杀死它之后不会显示片段布局
当我的Fragment
被销毁/再次加回时,曾经存在的Views
被销毁,我回到空白屏幕。我在我的Fragment
中有一个LinearLayout
,我添加了TextViews
。在重新创建LinearLayout
时调用.size()
显示正确的计数,但我无法弄清楚要调用什么以便再次显示它。我已经尝试在onResume()
中加入<LinearLayout>.requestLayout()
,但那不起作用。
让我知道我是否应该发布任何相关的代码。不过,我认为这些对我的片段来说并不是真的具体。
编辑:所以最初我在想,我将不得不处理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);
}
你能发布其中一个不起作用的片段吗?问题很可能出在您添加textviews的位置 – edthethird 2012-07-30 20:58:21
这是关于'ViewPager'的问题,它是支持库的一部分,而不是ViewPagerIndicator本身。 – 2012-07-30 21:05:37