After upgrading to Gradle 2.3. My project cannot compile. I'm having the log in the console
incompatible types: ObservableInt cannot be converted to int
Look at the generated file
android.databinding.ObservableInt viewModelLoadingVisibility;
this.vLoading.getRoot().setVisibility(viewModelLoadingVisibility);
In xml
file
<android.support.v7.widget.RecyclerView
android:id="@+id/rvProducts"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/white"
android:visibility="@{viewModel.contentVisibility}"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
/>
I tried in method in my binding class
@BindingAdapter("app:visibility")
public static void setViewVisible(View view, ObservableInt visible) {
int visibility = visible.get();
view.setVisibility(visibility);
}
and got log
warning: Application namespace for attribute app:visibility will be ignored.
public static void setViewVisible(View view, ObservableInt visible) {
warning: Use of ObservableField and primitive cousins directly as method parameters is deprecated and support will be removed soon. Use the contents as parameters instead in method public static void setViewVisible(android.view.View,android.databinding.ObservableInt)
public static void setViewVisible(View view, ObservableInt visible) {
Anyone encounters this?
You just have to add this to the bottom of your build.gradle dependencies:
See this: https://stackoverflow.com/a/42711830/376829 regarding GoMobile update to version "+eb90329 Mar 7 2017" and GoBind plugin revert to version "0.2.6" (although the current version is "0.2.8")
remember this
re-download the library from the Support repository in the Android SDK manager.
This looks like a bug. Please file it. There are many tests and we don't expect this kind of regression. It is important that we get your specific example so we can be sure it is caught.
You can ignore the warnings for now.
The first is caused because of this:
You should use this instead:
The second is because we support
ObservableInt
as a parameter. You typically don't want to acceptObservableInt
, but ratherint
instead. I'd love to see use cases whereObservableInt
is necessary. We may just remove that warning and support it always or we may pull the plug on supportingObservableInt
as a parameter if there are no valid uses.----- edit -----
I tested this with a little application and I didn't have any issue without any BindingAdapter. Here is the layout:
Here is my model:
Even when I used a BindingAdapter taking an ObservableInt, it worked. Here's my BindingAdapter:
And I changed the View's binding to be:
Is there something different about your
viewModel
?