Android onCreateView snippet creating repeating views on each other

In my application, when I pause, after resuming, I get duplicate views stacked on top of each other, with the topmost ones 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; } 
0
source share
1 answer

Your problem is not in onCreateView() , most likely. Instead, I suspect you are creating a fragment for the second time. You only need to create the fragment once, even if the activity is destroyed and recreated due to a configuration change (for example, portrait → landscape rotation).

+1
source

Source: https://habr.com/ru/post/1012584/


All Articles