Android Data binding create two Binding Adapters with same parameters

152
August 16, 2019, at 7:10 PM

I'm following MVVM Pattern + Data binding in android, I moved my whole UI logic to view (binding adapters or modify directly xml file using data binding) but I have a problem with binding adapters.

I want to create two binding adapters that share the same parameters but they will be triggered differently.

For example this is the binding adapter I created :

@BindingAdapter(
    value = ["user", "action", "viewModel", "displayTextView"],
    requireAll = false
)
fun Button.onUserDetailsButtonClicked(
    user: UserData,
    action: Action?,
    userVM: UserModel,
    display: textView
) {this.setOnClickListener{...}}

now I want to create another binding adapter that will share the same attributes but will be triggered with the event "onLongClick" on the button.

I tried to use the same function renamed and changed the content of the function but it's not working.

  @BindingAdapter(
        value = ["user", "action", "viewModel", "displayTextView"],
        requireAll = false
    )
    fun Button.onUserDetailsButtonLongClicked(
        user: UserData,
        action: Action?,
        userVM: UserModel,
        display: textView
    ) {this.setOnLongClickListener{... true}}

I tried also to add a new attribute (longclick = true) to put a difference between the two methods but it's not working too.

Is there a better way to create this binding adapters? ( Maybe I can avoid binding adapter in this case?)

Can I bind the fragment and call the methods from xml file or is that an anti pattern?

Rent Charter Buses Company
READ ALSO
how to set application theme in code rather than in manifest

how to set application theme in code rather than in manifest

I want my application to apply Leanback-theme on Android-TV, and AppCompat-theme on Android phones

126
Duplicate class found in modules with R8 enabled

Duplicate class found in modules with R8 enabled

I created two aar-libraries: comexample:test1:1

164
How to decrypt signal protocol message sent from node in android - java

How to decrypt signal protocol message sent from node in android - java

I'm setting up a connection between a laptop and an android phone with socketIOI wanted the messages to be encrypted with signal protocol, and so far I've been able to start a session and send a message from the phone to the laptop and decrypt it

137
Deside the host before connecting with WiFi Direct

Deside the host before connecting with WiFi Direct

How can you decide which phone would be the Group Owner of the Direct Network before connecting to it in Android Studio?

129