问题
I Have fragment 1, fragment 2, fragment 3 which are in the Main Activity. there is a TextView in the main Activity, how can the fragments change the text in the text view?
I already did the casting (Actvity).getActivity but i don't want my app to have error when changing Activities
回答1:
Write a setter method like setTextViewText(String str)
in the activity and from fragment call the method like ((YourActivity)getActivity()).setTexrViewText(str)
来源:https://stackoverflow.com/questions/29405335/how-to-change-data-of-main-activity-from-fragment