0

I have two tabs with fragments created in my activity, the data of the second tab depends on the first tab data.

Both the tabs are containing list items, when I delete an item from first tab's list, it gets deleted but the second tab still shows the data. I need to go back from activity and load again to see the updated data in second tab.

Is there any way that I can refresh the second tab content whenever I delete/update list item of first tab?

Note: I have tried -
detach()
attach()

and

runQueryOnBackgroundThread()
notifyDataSetChanged()

In onResume nothing seems to be working. Any help would help a lot

Flat Eric
  • 7,971
  • 9
  • 36
  • 45
abdulH
  • 375
  • 1
  • 6
  • 19

2 Answers2

1

You should learn about Interface communication. Read this http://developer.android.com/training/basics/fragments/communicating.html will help you.

Panther
  • 8,938
  • 3
  • 23
  • 34
0

you should override setUserVisibleHint method in your fragment and put your refreshing code in it

    @Override
    public void setUserVisibleHint(boolean isVisibleToUser) {
    super.setUserVisibleHint(isVisibleToUser);
       if (isVisibleToUser && isResumed()) {

       }
    }

I got this code in help.Hope it will help more people.Or refer my question here

http://stackoverflow.com/questions/40505019/how-to-refresh-tabs-content-dynamically-while-switching-between-one-tab-to-other/40505242#40505242

Deepa MG
  • 188
  • 1
  • 15