我在 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
}
我开始认为数据绑定不适用于偏好屏幕,有人可以帮忙吗?
如果需要,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