cv87
cv87

Reputation: 197

Passing data through tabs in android

Using ActionBar Sherlock to implements tabs, I have a new TabsAdapter object declared and two tabs added to it.

mTabsAdapter = new TabsAdapter(this, getSupportActionBar(), mViewPager);
mTabsAdapter.addTab(tab1, FragmentA.class);
mTabsAdapter.addTab(tab2, FragmentB.class);

There is some data in a hashmap that i would need to use in both FragmentA and FragmentB. Both these classes extend the android Fragment. I am not sure how to pass this data and retrieve it at the other end.

Thank you for the help

Upvotes: 2

Views: 2346

Answers (1)

Rajdeep Dua
Rajdeep Dua

Reputation: 11230

You can keep this data in activity in a class level field and access it from both the fragments.

A Fragment has access to activity instance using getActivity() method.

Upvotes: 4

Related Questions