weera
weera

Reputation: 944

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.

Upvotes: 17

Views: 22628

Answers (3)

Aks4125
Aks4125

Reputation: 5720

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.

Upvotes: 8

Hor Chanpheng
Hor Chanpheng

Reputation: 871

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"

Upvotes: 13

Victoria Gonda
Victoria Gonda

Reputation: 256

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

Upvotes: 22

Related Questions