如果动作条上的片段或活动处理? [英] Should the ActionBar be handled on Fragments or on the Activity?

查看:140
本文介绍了如果动作条上的片段或活动处理?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想提出一个购物清单应用程序,我有两个片段,一个 ProductListFragment ShoppingListFragment 。我有动作条按钮,在 ProductListFragment 列表 >。我的问题是,我应该处理的片段或上活动?

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?

推荐答案

您应该让您的活动来处理您的片段的事件。这可以让你的灵活性,您的设计,让您可以重用片段的其他活动的路线。 这里是如何做到这一点使用事件回调一个很好的例子。祝你好运。

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.

这篇关于如果动作条上的片段或活动处理?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆