Load and draw data from fragment or tablayout

SplinterSplinter RUMember ✭✭
edited March 2017 in Xamarin.Android

I have some dillema.
I have a fragment returns viewpager in tablayout with 3 fragments/tabs.
var activeOrders = new OrderListFragment("active"); var draftOrders = new OrderListFragment("draft"); var archiveOrders = new OrderListFragment("archive"); new Fragment[] { activeOrders, draftOrders, archiveOrders }; TabsAdapter adapter = new TabsAdapter(this.ChildFragmentManager, fragments); ordersViewPager.Adapter = adapter; ordersTabs.SetupWithViewPager(ordersViewPager);

I set some OrderListFragment string var from param in ctor of OrderListFragment to load data in OnViewCreated().
But OnViewCreated method only triggers my loading data method when I switch to second tab on viewpager. And it preloads contetview for next tab ofc.
So I guess the only way to make data loading for current visible tab is subscribing to tabchanged event and refreshing chosen tab.
Is this^ right dicision?

upd. I forgot that current tab is prealoded when i was on prev. tab.
So another question: it's okay for me to preload next tab when switching but how to force reloading prev. tab? Or refreshing data when tab is visible is more correct way?

Sign In or Register to comment.