Android fragment onCreateView creating duplicate views on top of each other

前提是你 提交于 2019-12-24 19:22:05

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!