-2

I have one fragment and that have some view element like textview buttons.

Now My problem is I have some service running background and it is checking data from server(Mysql) when these are some data it tells to Mainactivity.

Now on the basis of result I have to update fragment texeviews buttos.

  • This question already has an answer [here](http://stackoverflow.com/questions/19677218/refresh-a-fragment-from-its-parent-activity) and [here](http://stackoverflow.com/questions/15137425/how-to-update-fragment-content-from-activity-viewpager) – Somesh Kumar Feb 14 '17 at 04:57
  • create a method in your fragment, and call it from Activity: `fragment.updateUI(SomeData someData);` – Vladyslav Matviienko Feb 14 '17 at 06:14
  • Possible duplicate of [Android: what is the best way to update the Activity view from within a fragment?](http://stackoverflow.com/questions/33967201/android-what-is-the-best-way-to-update-the-activity-view-from-within-a-fragment) – Vladyslav Matviienko Feb 14 '17 at 06:14
  • call this method in fragment ((YourActivity)getActivity()).updateDatafromActivity(); – Zar E Ahmer Feb 15 '17 at 05:40
  • @Somesh Kumar I have tried and my textview is getting updated in Fragment but sometimes and some times it doesn't .Mostly on android 6.0.1 and above. – Ashutosh Singh Feb 16 '17 at 12:18
  • Thanks Somesh Kumar – Ashutosh Singh Sep 01 '17 at 07:16

1 Answers1

0

In fact the fragment is a section of activity.

In the activity,you will get the fragment which involve.

You get the fragment ,so you can do you want to do .

jianfeng
  • 26
  • 2