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.