简体   繁体   English

多个片段和活动都响应按钮单击活动

[英]multiple fragments and activity all responding to button click in activity

I have a multi-fragment form dividing sections of a form. 我有一个多片段表格,将表格的各个部分分开。 When the user is finished they hit the submit button at the bottom of the screen which is owned by the hosting activity. 当用户完成操作后,他们点击托管活动拥有的屏幕底部的“提交”按钮。 When the user clicks submit all the fragments should send their data to the activity and then the activity handles the networking. 当用户单击提交时,所有片段都应将其数据发送到活动,然后活动处理网络。 So I have onClick listeners set for the same button in every fragment, as well as the activity. 因此,我为每个片段以及活动中的同一按钮设置了onClick侦听器。 However when I hit submit onClick only runs once, in some fragment (never in the activity), when it should run 5 times (because I have 4 fragments and 1 activity). 但是,当我点击submit onClick时,它只在某个片段中运行一次(在活动中没有),应该在其中运行5次(因为我有4个片段和1个活动)。 Basically I need the fragments to deal with the click and then the activity deal with the same click. 基本上,我需要片段来处理单击,然后活动要处理相同的单击。

使用观察者设计模式,其中活动是主题,而片段是观察者

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM