Android Databinding On Inner Class Not Updating Textview
App runs but the TextView doesn't get update here is the relevant code. activity_picker_dashboard.xml
If you want to include a data binding layout from a regular layout, you need to find the root view of the layout and call bind()
on it. Maybe something like this:
@OverrideprotectedvoidonCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_picker_dashboard);
ViewbindingRoot= findViewById(R.id.toolbar);
LayoutHeaderBindingbinding= LayoutHeaderBinding.bind(bindingRoot);
ProfileResponse.PayloadprofilePayload=newProfileResponse.Payload();
profilePayload.setFirstName("Test");
binding.setProfilePayload(profilePayload);
}
However, it is better to make your Activity's layout a data binding layout and you won't have to do that extra work:
<?xml version="1.0" encoding="utf-8"?><layoutxmlns:android="http://schemas.android.com/apk/res/android"><data><variablename="profilePayload"type="myms.models.ProfileResponse.Payload"/></data><android.support.constraint.ConstraintLayoutandroid:layout_width="match_parent"android:layout_height="match_parent"><!-- Top header --><includelayout="@layout/layout_header"app:profilePayload="@{profilePayload}" /><!-- DrawerLayout --></android.support.constraint.ConstraintLayout></layout>
And then your binding code is much simpler and less error prone:
@OverrideprotectedvoidonCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ActivityPickerDashboardBindingbinding=
DataBindingUtil.setContentView(this, R.layout.activity_picker_dashboard);
ProfileResponse.PayloadprofilePayload=newProfileResponse.Payload();
profilePayload.setFirstName("Test");
binding.setProfilePayload(profilePayload);
}
On a different note, I think Android data binding and butterknife have significant overlap in functionality and I would recommend choosing one or the other, but not both.
Post a Comment for "Android Databinding On Inner Class Not Updating Textview"