I know that to access custom items of preference I need to override Preference and "onBindView" method, but overriding doesn't work, because "It's overriding nothing" and calling super.onBindView(view)
shows "Unresolved reference: onBindView" error. What an I supposed to do? There's just onBindViewHolder method, but it's completely different, isn't it?
Asked
Active
Viewed 388 times
0

Viktor
- 566
- 5
- 17
-
Preference doesn't have an onBindView function. So that's why it isn't recognized. Some of its subclasses do, but not the Preference class itself. What are you actually trying to do, in detail? – Gabe Sechan Dec 28 '20 at 03:39
-
@GabeSechan I need an access to my custom element in preference layout. That's my question about that https://stackoverflow.com/questions/65440759/how-to-handle-click-events-on-custom-items-in-the-preferencepreferencefragment – Viktor Dec 28 '20 at 03:52
-
1That answer is using the androidx Preference class, not the Android one (and the function name is onBindViewHolder, not onBindView). To use that solution, you'd need to switch all of your preference code to using androidx preferences and not baseline android. – Gabe Sechan Dec 28 '20 at 03:55
-
@GabeSechan I always use androidx classes(whenever it's possible). In this case I have "import androidx.preference.Preference" in my import section, so when I extend Preference, it's actually androidx.preference.Preference. So what to do now? Should I use onBindViewHolder for my needs? – Viktor Dec 28 '20 at 03:57
-
1Yes. If you look at the actual class doc for Androidx Preference, there is no onBindView function, but there is an onBindViewHolder. – Gabe Sechan Dec 28 '20 at 04:04
-
@GabeSechan but why there are so much examples of "onBindView"? And all of them has an "override" mark. For example, https://code.luasoftware.com/tutorials/android/override-layout-of-android-preference/ (the last code snippet) or even in my own question, which I referenced above. – Viktor Dec 28 '20 at 04:17
-
No clue, but here's the docs: https://developer.android.com/reference/androidx/preference/Preference#onBindViewHolder(androidx.preference.PreferenceViewHolder) – Gabe Sechan Dec 28 '20 at 04:35
-
1But note that the example you posted isn't using androidx (they link to the android preference class in their article). And while Android Preferences doesn't have an onBindView, several of its subclasses do. – Gabe Sechan Dec 28 '20 at 04:36
-
@GabeSechan ok, thx for the information – Viktor Dec 28 '20 at 04:49