带有片段的Android ViewSwitcher

时间:2014-08-31 19:05:57

标签: android android-layout android-fragments viewswitcher

我有一个包含项目列表的片段。单击某个项目时,我需要在另一个片段中显示该项目的详细信息。基本上我正在寻找类似于从另一个活动调用新活动的东西。由于我使用片段,我总是使用下面的代码来显示一个片段中的另一个片段:

FragmentTransaction transaction = getFragmentManager().beginTransaction();
Fragment fragment = new LoginFragment();
transaction.replace(R.id.login_Or_FeatureContainer, fragment);
transaction.commit();

在上面的例子中,我正在替换要呈现的新内容的布局。

除了替换之外还有其他选择吗?

由于我不确定如何从上面解释的场景切换到另一个片段,我正在尝试使用ViewSwitcher,如下所示:

<ViewSwitcher
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@+id/viewSwitcher" >

    <fragment
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:name="com.fragments.ItemFragment"
        android:id="@+id/fragment"
        tools:layout="@layout/fragment_item" />

    <fragment
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:name="com.fragments.Fragment_Offer_Voucher_Detail"
        android:id="@+id/fragment2"
        tools:layout="@layout/fragment_offer_detail" />
</ViewSwitcher>

这里我试图使用视图切换器切换到下一个片段。 但我的第二个片段是动态的 - 数据取决于第一个片段中点击的项目。

可以使用ViewSwitcher动态加载另一个片段吗?

感谢。

0 个答案:

没有答案
相关问题