2014-12-04 74 views
1

片段我在我的XML布局定义的片段,我想从我的fragmentactivity传递数据给它。那可能吗 ?我不想在运行时包含片段,因为我不打算在活动期间更改片段。 这里是我的xml将数据传递给静态包含从片段活动

<LinearLayout 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:orientation="vertical" > 

    <fragment 
     android:id="@+id/profileFragment" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     class="com.fragments.MyProfileFragment" > 
    </fragment> 

    <fragment 
     android:id="@+id/hoppiesFragment" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     class="com.fragments.HoppiesFragment" > 
    </fragment> 
</LinearLayout> 
+0

能否请您接受的答案吗? – 2014-12-04 11:57:24

+0

我接受了你的回答。谢谢:) – 2014-12-04 12:05:17

回答

2

使用FragmentManager#findFragmentById方法来获得片段和数据传递到它的一些公共方法。

+0

非常感谢您的快速回复。 :) – 2014-12-04 12:04:31

+0

我很高兴我可以帮助。 – 2014-12-04 12:05:32