Android 片段 onCreateView 在彼此之上创建重复的视图 [英] Android fragment onCreateView creating duplicate views on top of each other
本文介绍了Android 片段 onCreateView 在彼此之上创建重复的视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在我的应用程序中,当我暂停时,在恢复时,我会看到重复的视图堆叠在一起,最顶部是唯一可编辑的视图.我的 onCreateView() 在下面.有什么建议吗?
In my app, when I suspend, upon resume, I get duplicate views stacked on top of each other, with the topmost being the only editable ones. My onCreateView() is below. Any suggestions?
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View v = super.onCreateView(inflater, container, savedInstanceState);
Item currentItem = Global.DataManager.getItem();
// Set the different details
((EditView) v.findViewById(R.id.item_title))
.setText(currentItem.getTitle());
((EditView) v.findViewById(R.id.item_type))
.setText(currentItem.getType());
((EditView) v.findViewById(R.id.item_details))
.setText(currentItem.getDetails());
return v;
}
推荐答案
您的问题很可能不在 onCreateView()
中.相反,我怀疑您正在第二次创建片段.您只需创建一个片段一次,即使由于配置更改(例如,纵向 -> 横向旋转)而破坏并重新创建了 Activity.
Your problem is not in onCreateView()
, most likely. Instead, I suspect that you are creating the fragment a second time. You only need to create a fragment once, even if activity is destroyed and recreated due to a configuration change (e.g., portrait -> landscape rotation).
这篇关于Android 片段 onCreateView 在彼此之上创建重复的视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文