Joshua Steiner
Joshua Steiner

Reputation: 129

Android fragment onCreateView creating duplicate views on top of each other

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;
}

Upvotes: 1

Views: 1367

Answers (1)

CommonsWare
CommonsWare

Reputation: 1006819

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).

Upvotes: 1

Related Questions