Should the ActionBar be handled on Fragments or on

2019-08-12 19:24发布

问题:

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.