Android – 带有偏好活动的DataBinding

我build立了XML中的数据绑定 ,但是当我去偏好活动来实际设置绑定我不能。 数据绑定XML所在的文件称为preference.xml,所以我假设应该有一个名为PreferencesBinding的生成类,但是没有。 它应该不是自动生成的? 此外我的代码在preferenceActivity.java不会编译以下内容:

Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); PreferencesBinding binding = DataBindingUtil..... //what do put here ??? this is preferenceactivity not Activity Admin user = new Admin(true); binding.setUser(user);//this what i want to do addPreferencesFromResource(R.xml.preferences);//this would not be necessary if i can get dataBinding to work //..rest of code not important } 

我开始认为数据绑定不适用于首选项屏幕,任何人都可以帮忙吗?

如果neseccary的preferences.xml文件如下所示:

  <?xml version="1.0" encoding="utf-8"?> <layout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:customNS="http://schemas.android.com/apk/res/mypackage" > <data> <variable name="admin" type="mypackage.Administration"/> </data> <PreferenceScreen> <!-- ....bunch of preferences ... --> </PreferenceScreen> </layout 

Solutions Collecting From Web of "Android – 带有偏好活动的DataBinding"