Communication between xamarin fragments

I am using Xamarin for Android. I use the FragmentActivity ActionBarSherlock to have 4 tabs, each of which loads a fragment.

One of these tabs stores list (A), which contains the adapter containing the list that is displayed in the Snippet, and on the other tab is a simple snippet (B) that should add an item to the list.

How can I access the list from fragment B?

+4
source share
1 answer

Put the list in your main activity (FragmentActivity) as an open contributor or create its getter / setter. Now you can access this list in ListFragment (A) and in a simple fragment (B). This access in ListFragment and in a simple fragment can be done with:

var myList = ((FragmentActivity)this.Activity).getList(); 

So, the list is now available to all fragments inside your main activity fragment.

+1
source

Source: https://habr.com/ru/post/1489691/


All Articles