我在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