包含问题的Android重用布局

时间:2014-10-16 09:53:48

标签: java android android-layout user-interface android-fragments

我有几个布局:

loading.xml
reload.xml
noresult.xml

这些是LinearLayout和RelativeLayout

我在其他布局中使用它们如下:

<include
    android:id="@+id/loading"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerInParent="true"
    layout="@layout/loading"
    android:visibility="gone" />

<include
    android:id="@+id/reload"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerInParent="true"
    layout="@layout/reload"
    android:visibility="gone" />

<include
    android:id="@+id/noresult"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerInParent="true"
    layout="@layout/noresult"
    android:visibility="gone" />

问题在于我创建包含这些的通用布局,在多个片段中使用(例如在viewpager中)

当我在列表中单击重新加载布局的重新加载按钮时。它使用第一个数据重新加载另一个列表。

视图ID会出现问题吗?

我可以在多个布局中重复使用相同的包含不同的包含ID,但在include中具有相同的重新加载按钮ID,是否可以创建ID冲突? (这是我认为的同一个问题)

编辑1:

用于添加片段的代码:

getSherlockActivity().getSupportFragmentManager()
                                        .beginTransaction()
                                        .setCustomAnimations(R.anim.slide_in_bottom, R.anim.slide_out_top, R.anim.slide_in_top, R.anim.slide_out_bottom)
                                        .add(R.id.fragment_a, fragmentClassA1)
                                        .addToBackStack(TAG_A1)
                                        .commit();

1 个答案:

答案 0 :(得分:0)

您必须在布局本身之前选择布局组:

findViewById(R.id.loading).findViewById(android.R.id.list);
相关问题