0

As I can communicate a fragment that was added programmatically with an activity and that activity also can communicate with the fragment.

Activity

Activity

Fragment added programmatically

Fragment added programmatically

Daniel Orozco
  • 185
  • 10
  • 1
    Possible duplicate of [Communicating between a fragment and an activity - best practices.](http://stackoverflow.com/questions/14247954/communicating-between-a-fragment-and-an-activity-best-practices) – Taras Oct 10 '15 at 16:30

1 Answers1

2
  • Activity->Fragment: getSupportFragmentManager().findFragmentByXX()
  • Fragment->Activity: getActivity()

Also it is a common practice to use Interface to communicate between them. See https://developer.android.com/training/basics/fragments/communicating.html

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
Neil
  • 664
  • 6
  • 16