Updating the contents on tab changed in view pager

I am scracthing my head for past 1 day but unable to find the solution.
In mine application there are two tabs under the toolbar

  • First tab is USER-TAB

  • the second one is ADMIN-TAB

    In both the tabs there are the listView. When a ListItem on the USER-TAB is clicked a dialog appears and user take some action.

    Now after this when the ADMIN-TAB is Selected the Admin should get refreshed with new sets of data. But It’s not. On selecting the ADMIN-TAB the onResume() method and everyting is getting called but it is not able to update the list.

I wont be able to write the Whole code, I am giving some snippet.
Basically I have taken the code from this link


In My Main Activity I have written the OpPageChangeListener.

public class MaterialTab extends FragmentActivity {
    protected void onCreate(Bundle savedInstanceState) {
        // Get the ViewPager and set it's PagerAdapter so that it can display items
        ViewPager viewPager = (ViewPager) findViewById(R.id.viewpager);
        viewPager.setAdapter(new SampleFragmentPagerAdapter(getSupportFragmentManager()));
        // Give the PagerSlidingTabStrip the ViewPager
        PagerSlidingTabStrip tabsStrip = (PagerSlidingTabStrip) findViewById(R.id.tabs);
        // Attach the view pager to the tab strip
        tabsStrip.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
            public void onPageSelected(int position) {
                if(position == 0){
                    MileUserFragment userFragment = new MileUserFragment();
                    final FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
                } if(position == 1){
                    MileAdminFragment adminFragment = new MileAdminFragment();
                    final FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
            public void onPageScrollStateChanged(int state) {

OnPageSelected You can see I am detaching and reattaching the fragment.Everything is working fine. Both Fragments OnResume() are getting called but the List is not getting changed. I don’t undrstand why

Source: android

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.