2014-12-04 78 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