https://kotlinlang.org logo
#android
Title
# android
c

changhyun

06/22/2018, 5:41 AM
Copy code
android:layout_gravity="@{rankingItemViewModel.marginLeftOrRight  ? Gravity.RIGHT : Gravity.LEFT}"
Any one can tell me why its not working?
g

gildor

06/22/2018, 5:43 AM
It’s not a Kotlin related question
I suppose this is a problem of binding adapter, you can write your own
m

myanmarking

06/22/2018, 9:10 AM
i dont use databinding, but shoudnt it be strings:
Copy code
right
or
Copy code
bottom
?
g

gildor

06/22/2018, 9:20 AM
it depends on binding adapter
m

myanmarking

06/22/2018, 9:21 AM
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

gildor

06/22/2018, 9:22 AM
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

myanmarking

06/22/2018, 9:22 AM
just inspect the generated code and check why it is not working
g

gildor

06/22/2018, 9:23 AM
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

myanmarking

06/22/2018, 9:25 AM
but he wants to change the gravity based on a business logic variable. how can he do it using themes ?
g

gildor

06/22/2018, 9:41 AM
You can change theme using business logic %)
r

rkeazor

06/22/2018, 1:50 PM
This is not Kotlin related. but i can tell more than likely you forgot to import android.view in your xml
m

myanmarking

06/22/2018, 1:51 PM
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

rkeazor

06/22/2018, 1:52 PM
<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
3 Views