How to change data of Main Activity from Fragment [closed]

瘦欲@ 提交于 2021-02-08 08:00:40

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!