Android: Passing Objects Between Fragments

前端 未结 4 1888
旧巷少年郎
旧巷少年郎 2021-01-05 04:00

Before i start, i have look through question such as:

Passing data between fragments: screen overlap How to pass values between Fragments

as well as Android

4条回答
  •  一生所求
    2021-01-05 04:23

    I would normally have setters or methods similar to this in the containing activity.

    So if I understand correctly, you want the user to access RegistrationOneFragment, then when completed, use this data, validate it, and if valid, pass it along to RegistrationTwoFragment and move the user to this Fragment.

    Could you simply call validateJson(regData) in your onEmailRegistered method to handle the validation in your activity, if it succeeds, commit a transaction to RegistrationTwoFragment.

    Then all you need are getters and setters in your activity or Fragment to say getRegistrationOneData() in the activity or setData(Registration args) in the fragment as your examples show above.

    I don't know of any way to pass the args directly into the Fragment.

提交回复
热议问题