我有一個Fragment
,調用LoginRowFragment
,它在幾個其他Fragment
s或Activity
s中實例化。例如:立即更新片段的所有實例
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<fragment
android:id="@+id/loginrow"
class="com.mydomain.myproject.LoginRowFragment"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
由於這Fragment
在幾個地方被實例化時,我試圖找到一種方法來更新Fragment
的動作發生時的內容(在這種情況下,當用戶成功驗證自己) ,所以我想要立即更新Fragment
的所有實例,但由於這些Fragment
中的許多在識別時被分離,所以我找不到方法。
這是我迄今爲止嘗試:
設置一個
BroadcastReceiver
的Fragment
內。但是,Fragment
分離時不會觸發。爲每個實例設置相同的
id
。壞主意,它根本不起作用(基本上我已經嘗試過這種愚蠢行爲,因爲我已經用完了想法)。
這可能嗎?我怎樣才能做到這一點?
最後,這是我實現什麼(或非常相似),我把一個'Activity'內跟蹤活動的'Fragment's和在'的onResume更新他們的休息()'或'onAttach()'。謝謝! – nKn