I have a layout defined that contains 2 ViewStubs. They are defined as follows:
<ViewStub
android:id="@+id/top_divider_stub"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inflatedId="@+id/top_divider_layout"
android:layout="@layout/include_line_separator_horizontal"/>
<ViewStub
android:id="@+id/bottom_divider_stub"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inflatedId="@+id/bottom_divider_layout"
android:layout="@layout/include_line_separator_horizontal"/>
In my adapter, I'm trying to access the ViewStub through the ViewDataBinding generated by the DataBinding library, in my case it's TitleBinding. Attempting to do the following causes an error.
TitleBinding binding = DataBindingUtil.bind(view);
ViewStub topDividerStub = binding.topDividerStub;
ViewStub bottomDividerStub = binding.bottomDividerStub;
I receive this error and the application fails to compile.
Error:(31, 50) error: incompatible types: ViewStubProxy cannot be converted to ViewStub
I worked around it by setting the variable to type ViewStubProxy, allowing it to compile but giving an incompatible types syntax highlighting error. I'd like to know what the correct way of doing this if possible.
This works...
ViewStubProxy topDividerStub = binding.topDividerStub;
ViewStubProxy bottomDividerStub = binding.bottomDividerStub;
Resulting in

I have the same problem. It seems this is a bug of DataBinding. I'm not sure.
Or you can create a ViewStubProxy by yourself:
TitleBinding binding = DataBindingUtil.bind(view);
ViewStubProxy viewStubProxy = new ViewStubProxy((ViewStub) view.findViewById(R.id.viewStub));
viewStubProxy.setContainingBinding(binding);
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