gregkorossy / Android-Support-Preference-V7-Fix

Android androidx.preference support library has some issues, this lib tries to fix them.
https://discord.gg/87NVsSK
Apache License 2.0
497 stars 46 forks source link

Nested PreferenceScreen not opening on click. #159

Closed stevenliebregt closed 6 years ago

stevenliebregt commented 6 years ago

When using a nested preference screen with a PreferenceCompatFragment, and I click on it, it doesn't open, though when using an Activity it works. Are there things I should do extra to get it to work for fragments?

gregkorossy commented 6 years ago

Well, it seems like the default implementation only cares if the Activity handles it. However, there is a solution for nested fragments.

  1. Implement the screen callback (OnPreferenceStartScreenCallback) in your PreferenceCompatFragment class. You can see an example implementation in the MainActivity in the sample app.

  2. Add this to the same PreferenceCompatFragment:

    @Override
    public Fragment getCallbackFragment() {
    return this;
    // or you can return the parent fragment if it's handling the screen navigation, 
    // however, in that case you need to traverse to the implementing parent fragment
    }

    Explanation: The official library's implementation simply returns null so the handler skips over it even if the fragment implements OnPreferenceStartScreenCallback.

stevenliebregt commented 6 years ago

Thank you for the explanation.