I set up the data binding in xml but when i go to the preference activity to actually set up the binding i cant. The file where the data binding xml is in is called preference.xml so i assume there should be a generated class called PreferencesBinding but instead there is not. Should it not be auto generated ? Also my code in preferenceActivity.java wont compile the following:
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
}
i am starting to think data binding does not work for preference screens, can anyone help ?
the preferences.xml file if neseccary looks like this:
<?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
Stay organized with collections Save and categorize content based on your preferences. The @={} notation, which importantly includes the "=" sign, receives data changes to the property and listen to user updates at the same time. // Avoids infinite loops.
The bind method is the most complex code in the generated binding object, with a call to findViewById for each view to bind.
DataBinding for PreferenceScreen is not supported at the moment. It's cause of this xml is not layout xml. Also preference elements are not extending View or ViewGroup at all. Maybe this feature will be introduced at future, but not now. Only layout files can use DataBinding.
DataBinding for PreferenceScreen is still not supported. Android development is really inconsistent. Google tells us to use these new better technologies, but then you hit a brick-wall and have to do it the old way. You might as well just stuck with the old way all along.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With