user3026742
user3026742

Reputation: 31

while swiping the tabs ,oncreateView of Fragment is not called,how to call oncreateView every time

I have 3 tabs and i am using fragments.When the activity is first time called all the 3 fragments are generated. i have some check boxes on fragment1 and when I perform some actions on fragment1 and swipe, I want to call oncreateView of fragment3 again? Whenever i swipe or click on the tabs i want oncreateview called again as i am generating the fragment3 UI dynamically. If I go back to fragment1 and then come back to fragment3 ,i am seeing the changes.

a) My activity is extending FragmentActivity

public class AddProgramActivity extends FragmentActivity implements
ActionBar.TabListener

b) Adapter class is extending FragmentPagerAdapter

c) and my fragment classes are extending Fragment.

Please suggest how I can force my fragment 3 oncreateView is called every time I swipe or click on the tab or how to refresh every time I swipe.

Upvotes: 3

Views: 1105

Answers (1)

Thai Tran
Thai Tran

Reputation: 9935

I have the same problem like yours. My situation is trying to set back flags to disable the ActionBar buttons and call the invalidateOptionsMenu every time the view is created.

I have 3 tabs (corresponding to 3 fragments) on the actionbars. If I select from tab 1 to tab 2 and back to tab 1, then onCreateView of tab 1 is not called, but if I select from tab 1 to tab 3 and back to tab 1, then onCreateView of tab 1 is called

I cannot find any solution for this. My workaround is setting back the flags and call invalidateOptionsMenu in the function onTabSelected of TabListener

Somethings like this

ActionBar.TabListener tabListener = new ActionBar.TabListener() {
    public void onTabSelected(ActionBar.Tab tab, FragmentTransaction ft) {
        pager.setCurrentItem(tab.getPosition());

        MainFragmentActivity.disableBookmarkFlag = MainFragmentActivity.disableShareFlag = true;
        invalidateOptionsMenu();
    }

    .....
}

Hope this helps

Upvotes: 1

Related Questions