0

Possible Duplicate:
ViewPager Activity to notify a Fragment of a specific event

I am experimenting with using fragments and I ran into this problem. I have a service running in the background which I want to update a listview in a fragment. First I just wanted to have the fragment listen for a broadcast, but it seems like registerReceiver is not allowed in a fragment? How do I do this. Do I need to listen for a broadcast in the main activity and then somhow send it to the fragment?

4

1 に答える 1

2

これにはアクティビティを使用します。Google には、トピック フラグメントとアクティビティ コミュニケーションの良い例と説明がいくつかあります。ここでそれについて読むことができます: http://developer.android.com/training/basics/fragments/communicating.html

つまり、フラグメントはリスナーを使用してアクティビティと通信し、アクティビティはフラグメントでパブリック メソッドを使用するだけです。

于 2012-08-29T11:17:15.703 に答える