Could anyone help me please how can I import setFragmentResult and setFragmentResultListener into my project?
I have implemented 'androidx.fragment:fragment-ktx:1.2.5' but it seems it is not the right package.
First, make sure you have "androidx.fragment:fragment:1.3.0-alpha08"
as a dependency. These methods were added in 1.3.0-alpha04
, so make sure you have at least that version.
Then, these are the imports:
import androidx.fragment.app.setFragmentResult
and
import androidx.fragment.app.setFragmentResultListener
As of Feb'21, 1.3.0 is now available. Source
implementation 'androidx.fragment:fragment-ktx:1.3.0'
debugImplementation 'androidx.fragment:fragment-testing:1.3.0'
This should resolve the reference.
If you are using java please try this code below :
setFragmentResult :
requireActivity().getSupportFragmentManager().setFragmentResult("request_Key", new Bundle());
setFragmentResultListener :
requireActivity().getSupportFragmentManager().setFragmentResultListener("request Key", getViewLifecycleOwner(), new FragmentResultListener() {
@Override
public void onFragmentResult(@NonNull String requestKey, @NonNull Bundle result) {
}
});
dependency use :
implementation "androidx.fragment:fragment:1.3.0"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With