1

I have a ViewPager populated by Fragments. Especially, I have a Fragment that shows a list of Addresses objects and one that allows to create a new Address. The process to add a new Address is the following:

AddressListFragment --> CreateAddressFragment --> AddressListFragment

So when the new address is added, I come back to the AddressListFragment which is then the active one in the ViewPager. I need to update that fragment in order to update the list with the new added address when I come back on it ! Is there a specific method that I need to override on that fragment ?

Thanks in advance !

Hubert Solecki
  • 2,611
  • 5
  • 31
  • 63

2 Answers2

1

You should notify your adapter with notifyDataSetChanged() to update your list like

yourAdapter.notifyDataSetChanged();

kagkar
  • 469
  • 5
  • 15
  • Yes but where ? Which method of the fragment is called when I come back on it ? – Hubert Solecki Feb 09 '16 at 09:37
  • It doesn't matter. When you change something anywhere and anytime, you can notify adapter in the end and the adapter updates the list. – kagkar Feb 09 '16 at 09:39
  • Oh I see, I should get the address list binded to the adapter in ***AddressListFragment*** from the ***CreateAddressList***, add the new created address to it and call notifyDataSetChanged right. Will try it out ! – Hubert Solecki Feb 09 '16 at 09:44
0

In your AddressListFragment you can create Custom Broadcast Receiver and also register this Custom Broadcast Receiver in AddressListFragment. now send Broadcast message from CreateAddressFragment. when you send message at that time in your AddressListFragment receiver receive the message and you can do your task.

or if you want to create one method that call every time when you back to fragment then you can find best solution here

Community
  • 1
  • 1
Bhavesh Rangani
  • 1,490
  • 12
  • 23