-1

In my usecase, i am showing a TextView which when clicked pops up a Calendar. When the date is selected the calender view is closed and the TextView is populated with the selected date.

After a few experiments - i used a DialogFragment which pops up and closes as the date is selected. So far it is looking good.

The challenge is that i need to update the TextView in the parent activity with the date selected. Based on my knowledge using LocalBroadcastManager is one of the method, but is there something simpler? e.g. Activity getting the value directly from the DialogFragment or something on lines of startActivityWithResult?

Please suggest

Vivek
  • 156
  • 3
  • 18
  • http://stackoverflow.com/questions/10905312/receive-result-from-dialogfragment – Krish Feb 16 '17 at 15:16
  • Possible duplicate of [Get date from datepicker using dialogfragment](http://stackoverflow.com/questions/11527051/get-date-from-datepicker-using-dialogfragment) – Abhishek Jain Feb 16 '17 at 17:24

1 Answers1

2

Interfaces are very useful here

The easiest way to communicate between your activity and fragments is using interfaces. The idea is basically to define an interface inside a given fragment A and let the activity implement that interface.

Once it has implemented that interface, you could do anything you want in the method it overrides.

Check this answer

Community
  • 1
  • 1
Atef Hares
  • 4,715
  • 3
  • 29
  • 61