【问题标题】:Android fragment onCreateView creating duplicate views on top of each otherAndroid片段onCreateView在彼此之上创建重复视图
【发布时间】:2012-06-14 16:47:53
【问题描述】:

在我的应用程序中,当我暂停时,在恢复时,我会看到重复的视图堆叠在一起,最上面的是唯一可编辑的视图。我的 onCreateView() 在下面。有什么建议吗?

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

【问题讨论】:

    标签: android user-interface views


    【解决方案1】:

    您的问题很可能不在onCreateView() 中。相反,我怀疑您正在第二次创建片段。您只需要创建一次片段,即使由于配置更改(例如,纵向 -> 横向旋转)而破坏并重新创建活动也是如此。

    【讨论】:

    • 你完全正确。很抱歉延迟接受您的回答,但您的回答似乎是我的问题的原因。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-12-03
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多