首页 > 解决方案 > Custom Preference with AndroidX Preference

问题描述

Before AndroidX,
I would override the Preference's onCreateView(ViewGroup parent) method to pass Custom Layouts to be used as Preference.

But in AndroidX's Preference, there is no onCreateView(ViewGroup parent) method but it instead has onBindViewHolder(PreferenceViewHolder holder), I am not sure how to pass custom layouts & use them instead..

Any help would be highly appreciated!
Thanks!

标签: androidandroid-preferencesandroidx

解决方案


必须已经在构造函数中分配它:

this.setLayoutResource(R.layout.preferences);

以下是onBindViewHolder()的一些示例。


推荐阅读