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. 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). Basically I need the fragments to deal with the click and then the activity deal with the same click.
Asked
Active
Viewed 200 times
0
-
Do you have to set listener in each fragment ? is it possible for you to using functions which are belonged to your fragments, and calling them by fragments' instance.(Excuse ,my English is so pool) – jiar wang Jul 13 '18 at 01:09
-
1I wouldn't focus on the fragment trying to send the data to the activity. Instead I would have the fragment let the activity know that a submit action has taken place. The activity should then grab the required content from each fragment. In this route, the other fragments don't have to do anything at all as the activity will take responsibility for the data retrieval. – Matthew Cawley Jul 13 '18 at 02:12