Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

setFragmentResult and setFragmentResultListener packages not found (Unresolved reference)

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.

like image 665
weera Avatar asked Aug 24 '20 22:08

weera


3 Answers

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
like image 148
Victoria Gonda Avatar answered Oct 13 '22 22:10

Victoria Gonda


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.

like image 9
Aks4125 Avatar answered Oct 13 '22 22:10

Aks4125


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"
like image 8
Hor Chanpheng Avatar answered Oct 13 '22 22:10

Hor Chanpheng