问题
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