Reputation: 728
I hav a fragment in my MainActivity which displays a loading pic as of now, while I call a function in my XMLReader Application class from the MainActivity itself. The XMLReader uses an asynctask to read an xml file from an online server. after execution, i need to alert the fragment that currently shows the loading pic to refresh to something else. My question is how do i alert the currently displayed fragment? or atleast alert the Activity so that i can call a different fragment.
read somewhere that putting a broadcast listener would be overkill, is it my only way?
Upvotes: 0
Views: 83
Reputation: 4411
If you want to access the current visible item in viewpager:
// from activity
int position = mViewPager.getCurrentItem();
YourFragment yourFragment = (YourFragment) mSectionsPagerAdapter.getItem(position);
yourFragment.refreshSomething();
Upvotes: 0
Reputation: 16174
If you want to access the current visible item in viewpager:
// from activity
int position = mViewPager.getCurrentItem();
Fragment currentItem = mSectionsPagerAdapter.getItem(position);
If you want to callback the activity from fragment:
// call custom method update() in activity from fragment
((MainActivity) getActivity()).update();
Upvotes: 1