问题
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;
}
回答1:
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).
来源:https://stackoverflow.com/questions/11037752/android-fragment-oncreateview-creating-duplicate-views-on-top-of-each-other