0

So I have a fragment A which has a button to open another a fragment B. In fragment B I can pick some options, which is bundled into an Bundleobject. When I exit from fragment B, I want to refresh a TextView in fragment A.

Right now I'm using dismiss() method to remove the fragment, and then call back the fragment again so that onCreateView() is called. It works fine, but I don't want the animation where the fragment windows is run. So I like to not use dismiss() to remove the fragment instead I want to keep it on the Activity, but I need to know how I can refresh fragment A. I've tried overriding onActivityCreated() but it didn't result in the action I wanted.

So I wonder what's the approach if I want to refresh fragment A without having to dismiss it first so that onCreateView() can be called again.

I can attach code if needed. But maybe just an explanation is enough here?

starcorn
  • 8,261
  • 23
  • 83
  • 124
  • http://developer.android.com/training/basics/fragments/communicating.html – Raghunandan Jun 08 '14 at 09:19
  • @Raghunandan that one seems only to explain how you communicate to a fragment from e.g `MainActivity()` – starcorn Jun 08 '14 at 09:27
  • that explains how to use interface a callback to the activity. Then it explains how you communicate from activity to fragment. Which is what you want right? – Raghunandan Jun 08 '14 at 09:29
  • I want to pass data from fragment B to fragment A. A `TextView` in fragment A will then be updated. Both fragments extends the `DialogFragment` class. So it is not exactly communcation from activity to fragment. At least as what I understand it is. – starcorn Jun 08 '14 at 09:33
  • you haven't read the link properly. read it again. Fragment B -->Activity -->Fragment A – Raghunandan Jun 08 '14 at 09:34
  • ah yes you are right. I skimmed through it too fast ;) – starcorn Jun 08 '14 at 09:38

2 Answers2

0

you can use the life cycle function onResume() in fragment A to update the textview.

Ronn Wilder
  • 1,228
  • 9
  • 13
0

You can create your own Listener interface ( example how to do it or this) that listens when you remove your fragment, and you can get the event on Fragment A where you can setText to your TextView.

Community
  • 1
  • 1
Ultimo_m
  • 4,724
  • 4
  • 38
  • 60