To pass the fragment value in activity.

Asked 2 years ago, Updated 2 years ago, 78 views

I understand that activity uses Bundle, not int, to transfer fragment values.

(String value and image value go over and you have to pass it over. )

Please explain in more detail.

First, explain the sauce.

StartActivityForResult() for SecondActivity in MainActivity.

I'd like to send the result value back to Fragment.

(Fragment is the space to sprinkle a listview consisting of view pay on the MainActivity.)

android fragment onactivityresult

2022-09-22 13:38

1 Answers

Fragments within an activity are managed through Fragment Manager. Therefore, to access fragments from the activity, use the findFragmentById(intid) and findFragmentByTag(Stringtag) functions in FragmentManager.

The former is a function that is accessed through the android:id set in View, and the latter is accessed through the tag (unique string) set as the second parameter at FragmentTransaction.add(Fragment, String).

For related information, refer to activity and communication in the document below. (Reading the document in general as well as that section will help you deal with the fragments.)

The following is an example of the use of the findFragmentById(intid) function, as shown in the above document.

ExampleFragment fragment = (ExampleFragment) getFragmentManager().findFragmentById(R.id.example_fragment);


2022-09-22 13:38

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.