[英]Should the ActionBar be handled on Fragments or on the Activity?
I am making a shopping list app, and I have two Fragments
, a ProductListFragment
and a ShoppingListFragment
. 我正在制作一个购物清单应用程序,并且有两个
Fragments
,一个ProductListFragment
和ShoppingListFragment
。 I have ActionBar
buttons to add elements to the List
on ProductListFragment
. 我有
ActionBar
按钮,可将元素添加到ProductListFragment
上的List
中。 My question is, should I handle these buttons on the Fragment or on the Activity? 我的问题是,我应该处理“片段”还是“活动”上的这些按钮?
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.
祝好运。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.