``` android:layout_gravity="@{rankingItemViewMode...
# android
c
Copy code
android:layout_gravity="@{rankingItemViewModel.marginLeftOrRight  ? Gravity.RIGHT : Gravity.LEFT}"
Any one can tell me why its not working?
g
It’s not a Kotlin related question
I suppose this is a problem of binding adapter, you can write your own
m
i dont use databinding, but shoudnt it be strings:
Copy code
right
or
Copy code
bottom
?
g
it depends on binding adapter
m
oh i get it, in that case they must generate code for the binding, which is like setting it programatically. the sample looks good tho. what is the error ?
g
I use databindings but never use gravity in bindings, not sure how this should work.
Error is that no bindingadapter with int setter
I would suggest just to write own adapter
m
just inspect the generated code and check why it is not working
g
also looks like use viewmodel for changing gravity probably not the best idea, maybe theme would be better solution (you also can change theme with data bindings)
m
but he wants to change the gravity based on a business logic variable. how can he do it using themes ?
g
You can change theme using business logic %)
r
This is not Kotlin related. but i can tell more than likely you forgot to import android.view in your xml
m
you cannot change theme of an activity or widget. only at startup
can you?
only way for widgets is via XML, or just passing a wrapped context with ur theme. I dont think u can change theme without restarting it
r
<import type=“android.view.View”/>
you should put this in your xml
inside the data tag
you can’t access Gravity.Left or Gravity.right without it