Should the ActionBar be handled on Fragments or on the Activity?

僤鯓⒐⒋嵵緔 提交于 2020-01-06 01:46:34

问题


I am making a shopping list app, and I have two Fragments, a ProductListFragment and a ShoppingListFragment. I have ActionBar buttons to add elements to the List on ProductListFragment. My question is, should I handle these buttons on the Fragment or on the Activity?


回答1:


You should allow your Activity to handle the events of your fragments. This allows you flexibility in your design so that you can reuse your fragments in other Activities down the line. Here is a great example of how to accomplish this using event callbacks. Good luck.



来源:https://stackoverflow.com/questions/18617490/should-the-actionbar-be-handled-on-fragments-or-on-the-activity

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