Nested PreferenceScreen not opening on click.
Closed this issue · 2 comments
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?
Well, it seems like the default implementation only cares if the Activity
handles it. However, there is a solution for nested fragments.
-
Implement the screen callback (
OnPreferenceStartScreenCallback
) in yourPreferenceCompatFragment
class. You can see an example implementation in theMainActivity
in the sample app. -
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
.
Thank you for the explanation.